Skip to content

Commit a29b4e2

Browse files
authored
chore(testing): use source map support, improve test cleanup error handling VSCODE-593 (#784)
1 parent 93b63a4 commit a29b4e2

File tree

4 files changed

+62
-33
lines changed

4 files changed

+62
-33
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@
11741174
"process": "^0.11.10",
11751175
"sinon": "^9.2.4",
11761176
"sinon-chai": "^3.7.0",
1177+
"source-map-support": "^0.5.21",
11771178
"stream-browserify": "^3.0.0",
11781179
"terser-webpack-plugin": "^5.3.10",
11791180
"ts-loader": "^9.5.1",

src/test/runTest.ts

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,65 @@ async function startTestMongoDBServer() {
1717
});
1818
}
1919

20+
let testMongoDBServer: MongoCluster;
21+
22+
function cleanup() {
23+
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
24+
void testMongoDBServer?.close();
25+
}
26+
2027
async function main(): Promise<any> {
21-
const testMongoDBServer = await startTestMongoDBServer();
22-
23-
let failed = false;
24-
25-
try {
26-
// The folder containing the Extension Manifest package.json
27-
// Passed to `--extensionDevelopmentPath`
28-
const extensionDevelopmentPath = path.join(__dirname, '../../');
29-
30-
// The path to test runner pased to --extensionTestsPath
31-
const extensionTestsPath = path.join(__dirname, './suite/index');
32-
33-
// This is the workspace we open in our tests.
34-
const testWorkspace = path.join(__dirname, '../../out/test');
35-
36-
// Download VS Code, unzip it and run the integration test
37-
await runTests({
38-
version: 'insiders', // Download latest insiders.
39-
extensionDevelopmentPath,
40-
extensionTestsPath,
41-
launchArgs: [testWorkspace, '--disable-extensions'],
42-
});
43-
} catch (err) {
44-
console.error('Failed to run tests:');
45-
console.error(err);
46-
failed = true;
47-
} finally {
48-
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
49-
await testMongoDBServer.close();
50-
}
28+
testMongoDBServer = await startTestMongoDBServer();
5129

52-
if (failed) {
53-
process.exit(1);
54-
}
30+
// The folder containing the Extension Manifest package.json
31+
// Passed to `--extensionDevelopmentPath`
32+
const extensionDevelopmentPath = path.join(__dirname, '../../');
33+
34+
// The path to test runner passed to --extensionTestsPath
35+
const extensionTestsPath = path.join(__dirname, './suite/index');
36+
37+
// This is the workspace we open in our tests.
38+
const testWorkspace = path.join(__dirname, '../../out/test');
39+
40+
// Download VS Code, unzip it and run the integration test
41+
await runTests({
42+
version: 'insiders', // Download latest insiders.
43+
extensionDevelopmentPath,
44+
extensionTestsPath,
45+
launchArgs: [testWorkspace, '--disable-extensions'],
46+
});
47+
48+
cleanup();
5549
}
5650

51+
process.once('SIGINT', () => {
52+
console.log('Process was interrupted. Cleaning-up and exiting.');
53+
cleanup();
54+
process.kill(process.pid, 'SIGINT');
55+
});
56+
57+
process.once('SIGTERM', () => {
58+
console.log('Process was terminated. Cleaning-up and exiting.');
59+
cleanup();
60+
process.kill(process.pid, 'SIGTERM');
61+
});
62+
63+
process.once('uncaughtException', (err: Error) => {
64+
console.log('Uncaught exception. Cleaning-up and exiting.');
65+
cleanup();
66+
throw err;
67+
});
68+
69+
process.on('unhandledRejection', (err: Error) => {
70+
if (!err.message.match('Test run failed with code 1')?.[0]) {
71+
// Log an unhandled exception when it's not the regular test failure.
72+
// Test failures are logged in the test runner already so we avoid a generic message here.
73+
console.log('Unhandled exception. Cleaning-up and exiting.');
74+
console.error(err.stack || err.message || err);
75+
}
76+
77+
cleanup();
78+
process.exitCode = 1;
79+
});
80+
5781
void main();

src/test/suite/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sourceMapSupport from 'source-map-support';
2+
sourceMapSupport.install();
13
import Mocha from 'mocha';
24
import glob from 'glob';
35
import path from 'path';

0 commit comments

Comments
 (0)