99 LOG_PATH ,
1010 SKIP_COMPASS_DESKTOP_COMPILE ,
1111 SKIP_NATIVE_MODULE_REBUILD ,
12+ TEST_COMPASS_DESKTOP ,
1213 TEST_COMPASS_DESKTOP_PACKAGED_APP ,
1314 TEST_COMPASS_WEB ,
1415} from './test-runner-context' ;
@@ -26,6 +27,16 @@ import {
2627 removeUserDataDir ,
2728} from './compass' ;
2829
30+ export const globalFixturesAbortController = new AbortController ( ) ;
31+
32+ function throwIfAborted ( ) {
33+ if ( globalFixturesAbortController . signal . aborted ) {
34+ throw new Error ( 'Mocha run was aborted while global setup was in progress' ) ;
35+ }
36+ }
37+
38+ export let abortRunner : ( ( ) => void ) | undefined ;
39+
2940const debug = Debug ( 'compass-e2e-tests:mocha-global-fixtures' ) ;
3041
3142const wait = ( ms : number ) =>
@@ -47,74 +58,100 @@ const servers: MongoCluster[] = [];
4758 * - Compiles the desktop app
4859 */
4960export async function mochaGlobalSetup ( this : Mocha . Runner ) {
50- debug ( 'Unzipping fixtures...' ) ;
51- await gunzip ( path . join ( E2E_WORKSPACE_PATH , 'fixtures' , '*.gz' ) ) ;
52-
53- debug ( 'X DISPLAY' , process . env . DISPLAY ) ;
54-
55- if ( ! DISABLE_START_STOP ) {
56- debug ( 'Starting MongoDB servers' ) ;
57-
58- for ( const port of DEFAULT_CONNECTION_PORTS ) {
59- const server = await startTestServer ( {
60- args : [ '--port' , port ] ,
61- version :
62- process . env . MONGODB_VERSION ?? process . env . MONGODB_RUNNER_VERSION ,
63- } ) ;
64- servers . push ( server ) ;
65- cleanupFns . push ( ( ) => {
66- debug ( 'Stopping server at port %s' , port ) ;
67- return server . close ( ) ;
68- } ) ;
69- }
61+ abortRunner = ( ) => {
62+ globalFixturesAbortController . abort ( ) ;
63+ this . abort ( ) ;
64+ } ;
7065
71- if ( TEST_COMPASS_WEB ) {
72- debug ( 'Starting Compass Web' ) ;
73- const compassWeb = spawnCompassWeb ( ) ;
74- cleanupFns . push ( ( ) => {
75- if ( compassWeb . pid ) {
76- debug ( `Killing compass-web [${ compassWeb . pid } ]` ) ;
77- kill ( compassWeb . pid , 'SIGINT' ) ;
78- } else {
79- debug ( 'No pid for compass-web' ) ;
80- }
81- } ) ;
82- await waitForCompassWebToBeReady ( ) ;
66+ try {
67+ debug ( 'Unzipping fixtures...' ) ;
68+ await gunzip (
69+ path . join ( E2E_WORKSPACE_PATH , 'fixtures' , '*.gz' ) ,
70+ globalFixturesAbortController . signal
71+ ) ;
72+
73+ throwIfAborted ( ) ;
74+
75+ debug ( 'X DISPLAY' , process . env . DISPLAY ) ;
76+
77+ if ( ! DISABLE_START_STOP ) {
78+ debug ( 'Starting MongoDB servers' ) ;
79+
80+ for ( const port of DEFAULT_CONNECTION_PORTS ) {
81+ const server = await startTestServer ( {
82+ topology : 'replset' ,
83+ secondaries : 0 ,
84+ args : [ '--port' , String ( port ) ] ,
85+ version :
86+ process . env . MONGODB_VERSION ?? process . env . MONGODB_RUNNER_VERSION ,
87+ } ) ;
88+ servers . push ( server ) ;
89+ cleanupFns . push ( ( ) => {
90+ debug ( 'Stopping server at port %s' , port ) ;
91+ return server . close ( ) ;
92+ } ) ;
93+ throwIfAborted ( ) ;
94+ }
95+
96+ if ( TEST_COMPASS_WEB ) {
97+ debug ( 'Starting Compass Web' ) ;
98+ const compassWeb = spawnCompassWeb ( ) ;
99+ cleanupFns . push ( ( ) => {
100+ if ( compassWeb . pid ) {
101+ debug ( `Killing compass-web [${ compassWeb . pid } ]` ) ;
102+ kill ( compassWeb . pid , 'SIGINT' ) ;
103+ } else {
104+ debug ( 'No pid for compass-web' ) ;
105+ }
106+ } ) ;
107+ await waitForCompassWebToBeReady ( ) ;
108+ }
83109 }
84- }
85110
86- debug ( 'Getting mongodb server info' ) ;
87- await updateMongoDBServerInfo ( ) ;
111+ debug ( 'Getting mongodb server info' ) ;
112+ await updateMongoDBServerInfo ( ) ;
88113
89- try {
90- debug ( 'Clearing out past logs' ) ;
91- fs . rmdirSync ( LOG_PATH , { recursive : true } ) ;
92- } catch ( e ) {
93- debug ( '.log dir already removed' ) ;
94- }
114+ throwIfAborted ( ) ;
95115
96- fs . mkdirSync ( LOG_PATH , { recursive : true } ) ;
116+ try {
117+ debug ( 'Clearing out past logs' ) ;
118+ fs . rmdirSync ( LOG_PATH , { recursive : true } ) ;
119+ } catch ( e ) {
120+ debug ( '.log dir already removed' ) ;
121+ }
122+
123+ fs . mkdirSync ( LOG_PATH , { recursive : true } ) ;
97124
98- if ( TEST_COMPASS_DESKTOP_PACKAGED_APP ) {
99- debug ( 'Building Compass before running the tests ...' ) ;
100- await buildCompass ( ) ;
101- } else {
102- debug ( 'Preparing Compass before running the tests' ) ;
125+ if ( TEST_COMPASS_DESKTOP ) {
126+ if ( TEST_COMPASS_DESKTOP_PACKAGED_APP ) {
127+ debug ( 'Building Compass before running the tests ...' ) ;
128+ await buildCompass ( ) ;
129+ } else {
130+ debug ( 'Preparing Compass before running the tests' ) ;
103131
104- if ( ! SKIP_NATIVE_MODULE_REBUILD ) {
105- debug ( 'Rebuilding native modules ...' ) ;
106- await rebuildNativeModules ( ) ;
132+ if ( ! SKIP_NATIVE_MODULE_REBUILD ) {
133+ debug ( 'Rebuilding native modules ...' ) ;
134+ await rebuildNativeModules ( ) ;
135+ }
136+
137+ if ( ! SKIP_COMPASS_DESKTOP_COMPILE ) {
138+ debug ( 'Compiling Compass assets ...' ) ;
139+ await compileCompassAssets ( ) ;
140+ }
141+ }
107142 }
108143
109- if ( ! SKIP_COMPASS_DESKTOP_COMPILE ) {
110- debug ( 'Compiling Compass assets ...' ) ;
111- await compileCompassAssets ( ) ;
144+ throwIfAborted ( ) ;
145+
146+ cleanupFns . push ( ( ) => {
147+ removeUserDataDir ( ) ;
148+ } ) ;
149+ } catch ( err ) {
150+ if ( globalFixturesAbortController . signal . aborted ) {
151+ return ;
112152 }
153+ throw err ;
113154 }
114-
115- cleanupFns . push ( ( ) => {
116- removeUserDataDir ( ) ;
117- } ) ;
118155}
119156
120157export async function mochaGlobalTeardown ( ) {
@@ -127,13 +164,18 @@ export async function mochaGlobalTeardown() {
127164}
128165
129166function spawnCompassWeb ( ) {
130- const proc = crossSpawn . spawn ( 'npm' , [
131- 'run' ,
132- '--unsafe-perm' ,
133- 'start-web' ,
134- '--workspace' ,
135- '@mongodb-js/compass-web' ,
136- ] ) ;
167+ const proc = crossSpawn . spawn (
168+ 'npm' ,
169+ [ 'run' , '--unsafe-perm' , 'start' , '--workspace' , '@mongodb-js/compass-web' ] ,
170+ {
171+ env : {
172+ ...process . env ,
173+ OPEN_BROWSER : 'false' , // tell webpack dev server not to open the default browser
174+ DISABLE_DEVSERVER_OVERLAY : 'true' ,
175+ APP_ENV : 'webdriverio' ,
176+ } ,
177+ }
178+ ) ;
137179 proc . stdout . pipe ( process . stdout ) ;
138180 proc . stderr . pipe ( process . stderr ) ;
139181 return proc ;
@@ -143,6 +185,7 @@ async function waitForCompassWebToBeReady() {
143185 let serverReady = false ;
144186 const start = Date . now ( ) ;
145187 while ( ! serverReady ) {
188+ throwIfAborted ( ) ;
146189 if ( Date . now ( ) - start >= 120_000 ) {
147190 throw new Error (
148191 'The compass-web sandbox is still not running after 120000ms'
@@ -153,7 +196,7 @@ async function waitForCompassWebToBeReady() {
153196 serverReady = res . ok ;
154197 debug ( 'Web server ready:' , serverReady ) ;
155198 } catch ( err ) {
156- debug ( 'Failed to connect to dev server' , err ) ;
199+ debug ( 'Failed to connect to dev server: ' , ( err as any ) . message ) ;
157200 }
158201 await wait ( 1000 ) ;
159202 }
0 commit comments