@@ -3,6 +3,8 @@ import assert from 'node:assert/strict';
33import fs from 'node:fs' ;
44import path from 'node:path' ;
55
6+ import crossSpawn from 'cross-spawn' ;
7+ import kill from 'tree-kill' ;
68import yargs from 'yargs' ;
79import { hideBin } from 'yargs/helpers' ;
810import { pick } from 'lodash' ;
@@ -179,7 +181,9 @@ async function run() {
179181 ] )
180182 ) ;
181183
182- const { kind, filepath, appName } = await getTestSubject ( context ) ;
184+ const { kind, appName, filepath, autoUpdatable } = await getTestSubject (
185+ context
186+ ) ;
183187 const install = getInstaller ( kind ) ;
184188
185189 try {
@@ -190,7 +194,21 @@ async function run() {
190194 } ) ;
191195
192196 try {
193- runTest ( { appName, appPath } ) ;
197+ if ( context . platform === 'darwin' && process . env . CI ) {
198+ // Auto-update does not work on mac in CI at the moment. So in that case
199+ // we just run the E2E tests to make sure the app at least starts up.
200+ runE2ETest ( {
201+ appName,
202+ appPath,
203+ } ) ;
204+ } else {
205+ runUpdateTest ( {
206+ appName,
207+ appPath,
208+ autoUpdatable,
209+ testName : 'AUTO_UPDATE_FROM' ,
210+ } ) ;
211+ }
194212 } finally {
195213 await uninstall ( ) ;
196214 }
@@ -200,12 +218,53 @@ async function run() {
200218 }
201219}
202220
203- type RunTestOptions = {
221+ type AutoUpdateServerOptions = {
222+ port : number ;
223+ allowDowngrades ?: boolean ;
224+ } ;
225+
226+ function startAutoUpdateServer ( {
227+ port,
228+ allowDowngrades,
229+ } : AutoUpdateServerOptions ) {
230+ const env : Record < string , string > = {
231+ ...process . env ,
232+ PORT : port . toString ( ) ,
233+ } ;
234+ if ( allowDowngrades ) {
235+ env . UPDATE_CHECKER_ALLOW_DOWNGRADES = 'true' ;
236+ }
237+
238+ // a git repo that is not published to npm that evergreen clones for us in CI
239+ // next to the Compass code
240+ const cwd = path . join (
241+ __dirname ,
242+ '..' ,
243+ '..' ,
244+ '..' ,
245+ '..' ,
246+ 'compass-mongodb-com'
247+ ) ;
248+
249+ if ( ! fs . existsSync ( cwd ) ) {
250+ throw new Error ( `compass-mongodb-com does not exist: ${ cwd } ` ) ;
251+ }
252+
253+ console . log ( 'Starting auto-update server' , cwd ) ;
254+ return crossSpawn . spawn ( 'npm' , [ 'run' , 'start' ] , {
255+ env,
256+ cwd,
257+ stdio : 'inherit' ,
258+ shell : true ,
259+ } ) ;
260+ }
261+
262+ type RunE2ETestOptions = {
204263 appName : string ;
205264 appPath : string ;
206265} ;
207266
208- function runTest ( { appName, appPath } : RunTestOptions ) {
267+ function runE2ETest ( { appName, appPath } : RunE2ETestOptions ) {
209268 execute (
210269 'npm' ,
211270 [
@@ -229,6 +288,58 @@ function runTest({ appName, appPath }: RunTestOptions) {
229288 ) ;
230289}
231290
291+ type RunUpdateTestOptions = {
292+ appName : string ;
293+ appPath : string ;
294+ autoUpdatable ?: boolean ;
295+ testName : string ;
296+ } ;
297+
298+ function runUpdateTest ( {
299+ appName,
300+ appPath,
301+ autoUpdatable,
302+ testName,
303+ } : RunUpdateTestOptions ) {
304+ const server = startAutoUpdateServer ( {
305+ allowDowngrades : true ,
306+ port : 8080 ,
307+ } ) ;
308+ try {
309+ execute (
310+ 'npm' ,
311+ [
312+ 'run' ,
313+ '--unsafe-perm' ,
314+ 'test-packaged' ,
315+ '--workspace' ,
316+ 'compass-e2e-tests' ,
317+ '--' ,
318+ '--test-filter=auto-update' ,
319+ ] ,
320+ {
321+ // We need to use a shell to get environment variables setup correctly
322+ shell : true ,
323+ env : {
324+ ...process . env ,
325+ HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE : 'http://localhost:8080' ,
326+ AUTO_UPDATE_UPDATABLE : ( ! ! autoUpdatable ) . toString ( ) ,
327+ TEST_NAME : testName ,
328+ COMPASS_APP_NAME : appName ,
329+ COMPASS_APP_PATH : appPath ,
330+ } ,
331+ }
332+ ) ;
333+ } finally {
334+ if ( server . pid ) {
335+ console . log ( 'Stopping auto-update server' ) ;
336+ kill ( server . pid , 'SIGINT' ) ;
337+ } else {
338+ console . log ( 'cannnot stop auto-update server because no pid' ) ;
339+ }
340+ }
341+ }
342+
232343run ( )
233344 . then ( function ( ) {
234345 console . log ( 'done' ) ;
0 commit comments