Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(testing): use ts source map in tests, improve test cleanup error handling VSCODE-593 #784

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@
"process": "^0.11.10",
"sinon": "^9.2.4",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"stream-browserify": "^3.0.0",
"terser-webpack-plugin": "^5.3.10",
"ts-loader": "^9.5.1",
Expand Down
90 changes: 57 additions & 33 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,65 @@ async function startTestMongoDBServer() {
});
}

let testMongoDBServer: MongoCluster;

function cleanup() {
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
void testMongoDBServer?.close();
}

async function main(): Promise<any> {
const testMongoDBServer = await startTestMongoDBServer();

let failed = false;

try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.join(__dirname, '../../');

// The path to test runner pased to --extensionTestsPath
const extensionTestsPath = path.join(__dirname, './suite/index');

// This is the workspace we open in our tests.
const testWorkspace = path.join(__dirname, '../../out/test');

// Download VS Code, unzip it and run the integration test
await runTests({
version: 'insiders', // Download latest insiders.
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace, '--disable-extensions'],
});
} catch (err) {
console.error('Failed to run tests:');
console.error(err);
failed = true;
} finally {
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
await testMongoDBServer.close();
}
testMongoDBServer = await startTestMongoDBServer();

if (failed) {
process.exit(1);
}
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.join(__dirname, '../../');

// The path to test runner passed to --extensionTestsPath
const extensionTestsPath = path.join(__dirname, './suite/index');

// This is the workspace we open in our tests.
const testWorkspace = path.join(__dirname, '../../out/test');

// Download VS Code, unzip it and run the integration test
await runTests({
version: 'insiders', // Download latest insiders.
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace, '--disable-extensions'],
});

cleanup();
}

process.once('SIGINT', () => {
console.log('Process was interrupted. Cleaning-up and exiting.');
cleanup();
process.kill(process.pid, 'SIGINT');
});

process.once('SIGTERM', () => {
console.log('Process was terminated. Cleaning-up and exiting.');
cleanup();
process.kill(process.pid, 'SIGTERM');
});

process.once('uncaughtException', (err: Error) => {
console.log('Uncaught exception. Cleaning-up and exiting.');
cleanup();
throw err;
});

process.on('unhandledRejection', (err: Error) => {
if (!err.message.match('Test run failed with code 1')?.[0]) {
// Log an unhandled exception when it's not the regular test failure.
// Test failures are logged in the test runner already so we avoid a generic message here.
console.log('Unhandled exception. Cleaning-up and exiting.');
console.error(err.stack || err.message || err);
}

cleanup();
process.exitCode = 1;
});

void main();
2 changes: 2 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sourceMapSupport from 'source-map-support';
sourceMapSupport.install();
import Mocha from 'mocha';
import glob from 'glob';
import path from 'path';
Expand Down
Loading