@@ -17,41 +17,65 @@ async function startTestMongoDBServer() {
17
17
} ) ;
18
18
}
19
19
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
+
20
27
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 ( ) ;
51
29
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 ( ) ;
55
49
}
56
50
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
+
57
81
void main ( ) ;
0 commit comments