Skip to content

Commit 6911daf

Browse files
committed
feat(MongoMemoryServer): remove usage of "tmp" package
1 parent 3690a00 commit 6911daf

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

docs/api/interfaces/mongo-memory-instance-opts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ This options will get automatically set with a free port that is found.
6767
Typings: `dbPath?: string`
6868

6969
When set, adds the `--dbpath` argument with the input.
70-
This option will automatically be set with a directory generated by [`tmp`](https://www.npmjs.com/package/tmp).
70+
This option will automatically be set with a directory generated by [`mkdtemp`](https://nodejs.org/api/fs.html#fspromisesmkdtempprefix-options).
7171

7272
### storageEngine
7373

docs/guides/faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It is currently recommended to directly look at the TSDoc for these properties t
1313

1414
### Do testing database paths get cleaned up?
1515

16-
If the Database-path is a temporary directory (generated with `tmp`), then it will automatically get cleaned-up when calling `.stop()`, this can be disabled with `.stop(false)`.
16+
If the Database-path is a temporary directory (generated with `mkdtemp`), then it will automatically get cleaned-up when calling `.stop()`, this can be disabled with `.stop(false)`.
1717
If the Database-path is manually set with `dbPath`, then it needs to be manually cleaned-up with `.cleanup(true)`.
1818

1919
:::tip

packages/mongodb-memory-server-core/src/MongoMemoryServer.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SpawnOptions } from 'child_process';
2-
import * as tmp from 'tmp';
32
import getPort from 'get-port';
43
import {
54
assertion,
@@ -10,6 +9,8 @@ import {
109
statPath,
1110
ManagerAdvanced,
1211
Cleanup,
12+
createTmpDir,
13+
removeDir,
1314
} from './util/utils';
1415
import { MongoInstance, MongodOpts, MongoMemoryInstanceOpts } from './util/MongoInstance';
1516
import { MongoBinaryOpts } from './util/MongoBinary';
@@ -23,8 +24,6 @@ import * as os from 'os';
2324

2425
const log = debug('MongoMS:MongoMemoryServer');
2526

26-
tmp.setGracefulCleanup();
27-
2827
/**
2928
* MongoMemoryServer Stored Options
3029
*/
@@ -83,7 +82,7 @@ export interface StartupInstanceData {
8382
ip: NonNullable<MongoMemoryInstanceOpts['ip']>;
8483
storageEngine: NonNullable<MongoMemoryInstanceOpts['storageEngine']>;
8584
replSet?: NonNullable<MongoMemoryInstanceOpts['replSet']>;
86-
tmpDir?: tmp.DirResult;
85+
tmpDir?: string;
8786
keyfileLocation?: NonNullable<MongoMemoryInstanceOpts['keyfileLocation']>;
8887
launchTimeout?: NonNullable<MongoMemoryInstanceOpts['launchTimeout']>;
8988
}
@@ -382,12 +381,8 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
382381
if (isNullOrUndefined(this._instanceInfo)) {
383382
// create an tmpDir instance if no "dbPath" is given
384383
if (!data.dbPath) {
385-
data.tmpDir = tmp.dirSync({
386-
mode: 0o755,
387-
prefix: 'mongo-mem-',
388-
unsafeCleanup: true,
389-
});
390-
data.dbPath = data.tmpDir.name;
384+
data.tmpDir = await createTmpDir('mongo-mem-');
385+
data.dbPath = data.tmpDir;
391386

392387
isNew = true; // just to ensure "isNew" is "true" because an new temporary directory got created
393388
} else {
@@ -603,8 +598,8 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
603598
const tmpDir = this._instanceInfo.tmpDir;
604599

605600
if (!isNullOrUndefined(tmpDir)) {
606-
this.debug(`cleanup: removing tmpDir at ${tmpDir.name}`);
607-
tmpDir.removeCallback();
601+
this.debug(`cleanup: removing tmpDir at ${tmpDir}`);
602+
await removeDir(tmpDir);
608603
}
609604

610605
if (cleanup.force) {

0 commit comments

Comments
 (0)