Skip to content

Commit 4bf47e5

Browse files
authored
chore(test): update mongodb-runner usage (#611)
1 parent 3d70ba4 commit 4bf47e5

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@
4747
"watch": "npm run compile && npm-run-all -p watch:*",
4848
"watch:extension": "npm run compile:extension -- -watch",
4949
"watch:extension-bundles": "webpack --mode development --watch",
50-
"pretest": "npm run compile && mongodb-runner start --id=vscode -- --port 27088",
50+
"pretest": "npm run compile",
5151
"test": "npm run test-webview && npm run test-extension",
5252
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
5353
"test-webview": "jest",
54-
"posttest": "mongodb-runner stop --id=vscode",
5554
"analyze-bundle": "webpack --mode production --analyze",
5655
"vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production",
5756
"check": "npm run lint && npm run depcheck",
@@ -1067,7 +1066,7 @@
10671066
"mocha-junit-reporter": "^2.2.0",
10681067
"mocha-multi": "^1.1.7",
10691068
"mongodb-client-encryption": "^6.0.0",
1070-
"mongodb-runner": "^5.4.4",
1069+
"mongodb-runner": "^5.4.5",
10711070
"node-loader": "^0.6.0",
10721071
"npm-run-all": "^4.1.5",
10731072
"ora": "^5.4.1",

src/test/runTest.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
/* eslint-disable no-console */
12
import path from 'path';
23
import { runTests } from '@vscode/test-electron';
4+
import { MongoCluster } from 'mongodb-runner';
5+
import os from 'os';
6+
7+
import { TEST_DATABASE_PORT } from './suite/dbTestHelper';
38

49
// More information on vscode specific tests: https://github.com/microsoft/vscode-test
510

11+
async function startTestMongoDBServer() {
12+
console.log('Starting MongoDB server on port', TEST_DATABASE_PORT);
13+
return await MongoCluster.start({
14+
topology: 'standalone',
15+
tmpDir: path.join(os.tmpdir(), 'vscode-test-mongodb-runner'),
16+
args: ['--port', TEST_DATABASE_PORT],
17+
});
18+
}
19+
620
async function main(): Promise<any> {
21+
const testMongoDBServer = await startTestMongoDBServer();
22+
23+
let failed = false;
24+
725
try {
826
// The folder containing the Extension Manifest package.json
927
// Passed to `--extensionDevelopmentPath`
@@ -25,6 +43,13 @@ async function main(): Promise<any> {
2543
} catch (err) {
2644
console.error('Failed to run tests:');
2745
console.error(err);
46+
failed = true;
47+
} finally {
48+
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
49+
await testMongoDBServer.close();
50+
}
51+
52+
if (failed) {
2853
process.exit(1);
2954
}
3055
}

src/test/suite/dbTestHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import type { Document } from 'bson';
55
export const TEST_USER_USERNAME = 'testUser';
66
export const TEST_USER_PASSWORD = 'password';
77

8-
export const TEST_DATABASE_URI = 'mongodb://localhost:27088';
9-
export const TEST_DATABASE_URI_USER = `mongodb://${TEST_USER_USERNAME}:${TEST_USER_PASSWORD}@localhost:27088`;
8+
export const TEST_DATABASE_PORT = '27088';
9+
export const TEST_DATABASE_URI = `mongodb://localhost:${TEST_DATABASE_PORT}`;
10+
export const TEST_DATABASE_URI_USER = `mongodb://${TEST_USER_USERNAME}:${TEST_USER_PASSWORD}@localhost:${TEST_DATABASE_PORT}`;
1011

1112
export const TEST_DB_NAME = 'vscodeTestDatabaseAA';
1213

0 commit comments

Comments
 (0)