22import assert from 'node:assert/strict' ;
33import fs from 'node:fs' ;
44import path from 'node:path' ;
5- import { once } from 'node:events' ;
65
76import yargs from 'yargs' ;
87import { hideBin } from 'yargs/helpers' ;
98import { pick } from 'lodash' ;
10- import { execute , executeAsync } from './execute' ;
119import {
1210 type PackageDetails ,
1311 readPackageDetails ,
@@ -16,18 +14,22 @@ import {
1614import { createSandbox } from './directories' ;
1715import { downloadFile } from './downloads' ;
1816import { type PackageKind , SUPPORTED_PACKAGES } from './packages' ;
17+ import { getLatestRelease } from './releases' ;
18+ import { SUPPORTED_TESTS } from './tests/types' ;
1919import { type SmokeTestsContext } from './context' ;
2020
2121import { installMacDMG } from './installers/mac-dmg' ;
2222import { installMacZIP } from './installers/mac-zip' ;
2323import { installWindowsZIP } from './installers/windows-zip' ;
2424import { installWindowsMSI } from './installers/windows-msi' ;
2525
26+ import { testTimeToFirstQuery } from './tests/time-to-first-query' ;
27+ import { testAutoUpdateFrom } from './tests/auto-update-from' ;
28+ import { testAutoUpdateTo } from './tests/auto-update-to' ;
29+
2630const SUPPORTED_PLATFORMS = [ 'win32' , 'darwin' , 'linux' ] as const ;
2731const SUPPORTED_ARCHS = [ 'x64' , 'arm64' ] as const ;
2832
29- const SUPPORTED_TESTS = [ 'time-to-first-query' , 'auto-update-from' ] as const ;
30-
3133function isSupportedPlatform (
3234 value : unknown
3335) : value is typeof SUPPORTED_PLATFORMS [ number ] {
@@ -198,9 +200,13 @@ async function run() {
198200 ] )
199201 ) ;
200202
201- const { kind, appName, filepath, autoUpdatable } = await getTestSubject (
202- context
203- ) ;
203+ const {
204+ kind,
205+ appName,
206+ filepath,
207+ buildInfo : { channel, version } ,
208+ autoUpdatable,
209+ } = await getTestSubject ( context ) ;
204210 const install = getInstaller ( kind ) ;
205211
206212 try {
@@ -209,27 +215,51 @@ async function run() {
209215 }
210216
211217 for ( const testName of context . tests ) {
218+ const installerPath =
219+ testName === 'auto-update-to'
220+ ? await getLatestRelease (
221+ channel ,
222+ context . arch ,
223+ kind ,
224+ context . forceDownload
225+ )
226+ : filepath ;
227+
212228 const { appPath, uninstall } = install ( {
213229 appName,
214- filepath,
230+ filepath : installerPath ,
215231 destinationPath : context . sandboxPath ,
216232 } ) ;
217233
218234 try {
219235 if ( testName === 'time-to-first-query' ) {
220236 // Auto-update does not work on mac in CI at the moment. So in that case
221237 // we just run the E2E tests to make sure the app at least starts up.
222- runTimeToFirstQuery ( {
238+ testTimeToFirstQuery ( {
223239 appName,
224240 appPath,
225241 } ) ;
226242 }
227243 if ( testName === 'auto-update-from' ) {
228- await runUpdateTest ( {
244+ await testAutoUpdateFrom ( {
245+ appName,
246+ appPath,
247+ autoUpdatable,
248+ } ) ;
249+ }
250+ if ( testName === 'auto-update-to' ) {
251+ assert (
252+ context . bucketKeyPrefix !== undefined ,
253+ 'Bucket key prefix is needed to download'
254+ ) ;
255+
256+ await testAutoUpdateTo ( {
229257 appName,
230258 appPath,
231259 autoUpdatable,
232- testName,
260+ channel,
261+ bucketKeyPrefix : context . bucketKeyPrefix ,
262+ version,
233263 } ) ;
234264 }
235265 } finally {
@@ -246,110 +276,6 @@ async function run() {
246276 }
247277}
248278
249- async function importUpdateServer ( ) {
250- try {
251- return ( await import ( 'compass-mongodb-com' ) ) . default ;
252- } catch ( err : unknown ) {
253- console . log ( 'Remember to npm link compass-mongodb-com' ) ;
254- throw err ;
255- }
256- }
257-
258- async function startAutoUpdateServer ( ) {
259- console . log ( 'Starting auto-update server' ) ;
260- const { httpServer, updateChecker, start } = ( await importUpdateServer ( ) ) ( ) ;
261- start ( ) ;
262- await once ( updateChecker , 'refreshed' ) ;
263-
264- return httpServer ;
265- }
266-
267- type RunE2ETestOptions = {
268- appName : string ;
269- appPath : string ;
270- } ;
271-
272- function runTimeToFirstQuery ( { appName, appPath } : RunE2ETestOptions ) {
273- execute (
274- 'npm' ,
275- [
276- 'run' ,
277- '--unsafe-perm' ,
278- 'test-packaged' ,
279- '--workspace' ,
280- 'compass-e2e-tests' ,
281- '--' ,
282- '--test-filter=time-to-first-query' ,
283- ] ,
284- {
285- // We need to use a shell to get environment variables setup correctly
286- shell : true ,
287- env : {
288- ...process . env ,
289- COMPASS_APP_NAME : appName ,
290- COMPASS_APP_PATH : appPath ,
291- } ,
292- }
293- ) ;
294- }
295-
296- type RunUpdateTestOptions = {
297- appName : string ;
298- appPath : string ;
299- autoUpdatable ?: boolean ;
300- testName : string ;
301- } ;
302-
303- async function runUpdateTest ( {
304- appName,
305- appPath,
306- autoUpdatable,
307- testName,
308- } : RunUpdateTestOptions ) {
309- process . env . PORT = '0' ; // dynamic port
310- process . env . UPDATE_CHECKER_ALLOW_DOWNGRADES = 'true' ;
311-
312- const server = await startAutoUpdateServer ( ) ;
313-
314- const address = server . address ( ) ;
315- assert ( typeof address === 'object' && address !== null ) ;
316- const port = address . port ;
317- const HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE = `http://localhost:${ port } ` ;
318- console . log ( { HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE } ) ;
319-
320- try {
321- // must be async because the update server is running in the same process
322- await executeAsync (
323- 'npm' ,
324- [
325- 'run' ,
326- '--unsafe-perm' ,
327- 'test-packaged' ,
328- '--workspace' ,
329- 'compass-e2e-tests' ,
330- '--' ,
331- '--test-filter=auto-update' ,
332- ] ,
333- {
334- // We need to use a shell to get environment variables setup correctly
335- shell : true ,
336- env : {
337- ...process . env ,
338- HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE ,
339- AUTO_UPDATE_UPDATABLE : ( ! ! autoUpdatable ) . toString ( ) ,
340- TEST_NAME : testName ,
341- COMPASS_APP_NAME : appName ,
342- COMPASS_APP_PATH : appPath ,
343- } ,
344- }
345- ) ;
346- } finally {
347- console . log ( 'Stopping auto-update server' ) ;
348- server . close ( ) ;
349- delete process . env . UPDATE_CHECKER_ALLOW_DOWNGRADES ;
350- }
351- }
352-
353279run ( )
354280 . then ( function ( ) {
355281 console . log ( 'done' ) ;
0 commit comments