@@ -30,6 +30,7 @@ const wait = (ms: number) =>
3030
3131const allowedArgs = [
3232 '--test-compass-web' ,
33+ '--test-compass-web-atlas-cloud' ,
3334 '--no-compile' ,
3435 '--no-native-modules' ,
3536 '--test-packaged-app' ,
@@ -47,60 +48,97 @@ for (const arg of process.argv) {
4748 }
4849}
4950
51+ const disableStartStop = process . argv . includes ( '--disable-start-stop' ) ;
52+ const shouldTestCompassWebAtlasCloud = process . argv . includes (
53+ '--test-compass-web-atlas-cloud'
54+ ) ;
55+ const shouldTestCompassWeb =
56+ process . argv . includes ( '--test-compass-web' ) || shouldTestCompassWebAtlasCloud ;
57+
5058// We can't import mongodb here yet because native modules will be recompiled
5159let metricsClient : MongoClient ;
5260
5361const FIRST_TEST = 'tests/time-to-first-query.test.ts' ;
5462
55- let compassWeb : ChildProcessWithoutNullStreams ;
63+ let compassWeb : ChildProcessWithoutNullStreams | undefined ;
5664
5765async function setup ( ) {
5866 debug ( 'X DISPLAY' , process . env . DISPLAY ) ;
5967
60- const disableStartStop = process . argv . includes ( '--disable-start-stop' ) ;
61- const shouldTestCompassWeb = process . argv . includes ( '--test-compass-web' ) ;
62-
6368 // When working on the tests it is faster to just keep the server running.
6469 if ( ! disableStartStop ) {
6570 debug ( 'Starting MongoDB server' ) ;
6671 crossSpawn . sync ( 'npm' , [ 'run' , 'start-servers' ] , { stdio : 'inherit' } ) ;
6772
6873 if ( shouldTestCompassWeb ) {
69- debug ( 'Starting Compass Web' ) ;
70- compassWeb = crossSpawn . spawn (
71- 'npm' ,
72- [ 'run' , '--unsafe-perm' , 'start-web' ] ,
73- {
74- cwd : path . resolve ( __dirname , '..' , '..' ) ,
75- env : {
76- ...process . env ,
77- OPEN_BROWSER : 'false' , // tell webpack dev server not to open the default browser
78- DISABLE_DEVSERVER_OVERLAY : 'true' ,
79- APP_ENV : 'webdriverio' ,
80- } ,
81- }
82- ) ;
74+ debug ( 'Starting Compass Web' , { shouldTestCompassWebAtlasCloud } ) ;
75+
76+ const spawnCommand : [ string , string [ ] ] = shouldTestCompassWebAtlasCloud
77+ ? [
78+ 'npx' ,
79+ [
80+ 'ts-node' ,
81+ path . resolve (
82+ __dirname ,
83+ 'scripts' ,
84+ 'start-compass-web-with-atlas-auth.ts'
85+ ) ,
86+ ] ,
87+ ]
88+ : [
89+ 'npm' ,
90+ [
91+ 'run' ,
92+ '--workspace' ,
93+ '@mongodb-js/compass-web' ,
94+ '--unsafe-perm' ,
95+ 'start' ,
96+ ] ,
97+ ] ;
98+
99+ compassWeb = crossSpawn . spawn ( ...spawnCommand , {
100+ env : {
101+ ...process . env ,
102+ OPEN_BROWSER : 'false' , // tell webpack dev server not to open the default browser
103+ DISABLE_DEVSERVER_OVERLAY : 'true' ,
104+ APP_ENV : 'webdriverio' ,
105+ } ,
106+ } ) ;
83107
84108 compassWeb . stdout . pipe ( process . stdout ) ;
85109 compassWeb . stderr . pipe ( process . stderr ) ;
86110
87111 let serverReady = false ;
88112 const start = Date . now ( ) ;
113+ const timeout = shouldTestCompassWebAtlasCloud ? 240_000 : 120_000 ;
89114 while ( ! serverReady ) {
90- if ( Date . now ( ) - start >= 120_000 ) {
115+ if ( Date . now ( ) - start >= timeout ) {
91116 throw new Error (
92117 'The compass-web sandbox is still not running after 120000ms'
93118 ) ;
94119 }
95120 try {
96121 const res = await fetch ( 'http://localhost:7777' ) ;
97122 serverReady = res . ok ;
123+ if ( shouldTestCompassWebAtlasCloud ) {
124+ // TODO: we probably want to have just one endpoint for the sandbox
125+ // healthcheck sort of stuff
126+ const authRes = await fetch ( 'http://localhost:7777/projectId' ) ;
127+ serverReady = authRes . ok ;
128+ }
98129 debug ( 'Web server ready: %s' , serverReady ) ;
99130 } catch ( err ) {
100131 debug ( 'Failed to connect to dev server: %s' , ( err as any ) . message ) ;
101132 }
102133 await wait ( 1000 ) ;
103134 }
135+ if ( shouldTestCompassWebAtlasCloud ) {
136+ // Now wait for the cert to be issued
137+ // TODO: same as above, probably better to have just one nedpoint we can
138+ // ping to wait for everything to be ready
139+ debug ( 'Waitiing for x509 cert to propagate to Atlas clusters...' ) ;
140+ await fetch ( 'http://localhost:7777/x509' ) ;
141+ }
104142 } else {
105143 debug ( 'Writing electron-versions.json' ) ;
106144 crossSpawn . sync ( 'scripts/write-electron-versions.sh' , [ ] , {
@@ -136,11 +174,8 @@ function getResources() {
136174function cleanup ( ) {
137175 removeUserDataDir ( ) ;
138176
139- const disableStartStop = process . argv . includes ( '--disable-start-stop' ) ;
140- const shouldTestCompassWeb = process . argv . includes ( '--test-compass-web' ) ;
141-
142177 if ( ! disableStartStop ) {
143- if ( shouldTestCompassWeb ) {
178+ if ( compassWeb ) {
144179 debug ( 'Stopping compass-web' ) ;
145180 try {
146181 if ( compassWeb . pid ) {
@@ -199,8 +234,6 @@ function cleanup() {
199234async function main ( ) {
200235 await setup ( ) ;
201236
202- const shouldTestCompassWeb = process . argv . includes ( '--test-compass-web' ) ;
203-
204237 if ( ! shouldTestCompassWeb ) {
205238 if ( ! process . env . CHROME_VERSION ) {
206239 // written during setup() if disableStartStop is false
0 commit comments