Skip to content

Commit

Permalink
chore: update mongodb-runner to start and stop outside package
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy committed Nov 10, 2023
1 parent 65e2101 commit 899a15a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
"watch": "npm run compile && npm-run-all -p watch:*",
"watch:extension": "npm run compile:extension -- -watch",
"watch:extension-bundles": "webpack --mode development --watch",
"pretest": "npm run compile && mongodb-runner start --id=vscode -- --port 27088",
"pretest": "npm run compile",
"start-test-server": "mongodb-runner start --id=vscode --port 27088",
"stop-test-server": "mongodb-runner stop --id=vscode",
"test": "npm run test-webview && npm run test-extension",
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
"test-webview": "jest",
"posttest": "mongodb-runner stop --id=vscode",
"analyze-bundle": "webpack --mode production --analyze",
"vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production",
"check": "npm run lint && npm run depcheck",
Expand Down Expand Up @@ -1022,6 +1023,7 @@
"@types/babel__core": "^7.20.1",
"@types/babel__traverse": "^7.20.1",
"@types/chai": "^4.3.5",
"@types/cross-spawn": "^6.0.5",
"@types/debug": "^4.1.8",
"@types/enzyme": "^3.10.13",
"@types/glob": "^7.2.0",
Expand All @@ -1047,6 +1049,7 @@
"chalk": "^4.1.2",
"cli-ux": "^5.6.7",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"css-loader": "^6.8.1",
"depcheck": "^1.4.3",
"download": "^8.0.0",
Expand Down
30 changes: 30 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import path from 'path';
import { runTests } from '@vscode/test-electron';
import crossSpawn from 'cross-spawn';
import fs from 'fs';

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

function startTestMongoDBServer() {
console.log('Starting MongoDB server');

Check warning on line 9 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (ubuntu-latest)

Unexpected console statement

Check warning on line 9 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (macos-latest)

Unexpected console statement
crossSpawn.sync('npm', ['run', 'start-test-server'], { stdio: 'inherit' });
}

function cleanupTestMongoDBServer() {
console.log('Stopping MongoDB server and cleaning up server data');

Check warning on line 14 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (ubuntu-latest)

Unexpected console statement

Check warning on line 14 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (macos-latest)

Unexpected console statement
try {
crossSpawn.sync('npm', ['run', 'stop-test-server'], {
// If it's taking too long we might as well kill the process and
// move on, mongodb-runner is flaky sometimes.
timeout: 30_000,
stdio: 'inherit',
});
} catch (e) {
console.error('Failed to stop MongoDB Server', e);
}
try {
fs.rmdirSync('.mongodb', { recursive: true });

Check warning on line 26 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (ubuntu-latest)

Unexpected sync method: 'rmdirSync'

Check warning on line 26 in src/test/runTest.ts

View workflow job for this annotation

GitHub Actions / Test and Build (macos-latest)

Unexpected sync method: 'rmdirSync'
} catch (e) {
console.error('Failed to clean up server data', e);
}
}

async function main(): Promise<any> {
startTestMongoDBServer();

try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
Expand All @@ -26,6 +54,8 @@ async function main(): Promise<any> {
console.error('Failed to run tests:');
console.error(err);
process.exit(1);
} finally {
cleanupTestMongoDBServer();
}
}

Expand Down

0 comments on commit 899a15a

Please sign in to comment.