Skip to content

Commit 962fd67

Browse files
committed
fix: tune tmp dir opts, add debug info, add test for 4.0.3
Related #89
1 parent e826566 commit 962fd67

File tree

6 files changed

+108
-1113
lines changed

6 files changed

+108
-1113
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"devDependencies": {
2828
"@babel/cli": "^7.0.0",
2929
"@babel/core": "^7.0.0",
30+
"@babel/node": "^7.0.0",
3031
"@babel/plugin-proposal-class-properties": "^7.0.0",
3132
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
3233
"@babel/plugin-proposal-optional-chaining": "^7.0.0",

src/MongoMemoryServer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ export default class MongoMemoryServer {
112112
if (instOpts.dbPath) {
113113
data.dbPath = instOpts.dbPath;
114114
} else {
115-
tmpDir = tmp.dirSync({ prefix: 'mongo-mem-', unsafeCleanup: true });
115+
tmpDir = tmp.dirSync({
116+
prefix: 'mongo-mem-',
117+
unsafeCleanup: true,
118+
discardDescriptor: true,
119+
mode: '0755',
120+
});
116121
data.dbPath = tmpDir.name;
117122
}
118123

src/util/MongoBinary.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export default class MongoBinary {
3434
: false,
3535
};
3636

37-
const { downloadDir, platform, arch, version } = Object.assign({}, defaultOptions, opts);
38-
3937
let debug;
4038
if (opts.debug) {
4139
if (opts.debug.call && typeof opts.debug === 'function' && opts.debug.apply) {
@@ -47,6 +45,11 @@ export default class MongoBinary {
4745
debug = (msg: string) => {}; // eslint-disable-line
4846
}
4947

48+
const options = { ...defaultOptions, ...opts };
49+
debug(`MongoBinary options: ${JSON.stringify(options)}`);
50+
51+
const { downloadDir, platform, arch, version } = options;
52+
5053
if (this.cache[version]) {
5154
debug(`MongoBinary: found cached binary path for ${version}`);
5255
} else {

src/util/MongoInstance.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export default class MongodbInstance {
168168
this.instanceFailed('Data directory not found');
169169
} else if (/shutting down with code/i.test(log)) {
170170
this.instanceFailed('Mongod shutting down');
171+
} else if (/\*\*\*aborting after/i.test(log)) {
172+
this.instanceFailed('Mongod internal error');
171173
}
172174
}
173175
}

src/util/__tests__/MongoInstance-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,15 @@ describe('MongoInstance', () => {
137137
await mongod.kill();
138138
expect(isPidRunning(pid)).toBeFalsy();
139139
});
140+
141+
it('should work with mongodb 4.0.3', async () => {
142+
const mongod = await MongoInstance.run({
143+
instance: { port: 27445, dbPath: tmpDir.name },
144+
binary: { version: '4.0.3' },
145+
debug: true,
146+
});
147+
const pid: any = mongod.getPid();
148+
expect(pid).toBeGreaterThan(0);
149+
await mongod.kill();
150+
});
140151
});

0 commit comments

Comments
 (0)