11#!/usr/bin/env npx ts-node
2- import assert from 'node:assert/strict' ;
3- import fs from 'node:fs' ;
4- import path from 'node:path' ;
5-
62import yargs from 'yargs' ;
73import { hideBin } from 'yargs/helpers' ;
84import { pick } from 'lodash' ;
9- import {
10- type PackageDetails ,
11- readPackageDetails ,
12- writeAndReadPackageDetails ,
13- } from './build-info' ;
14- import { createSandbox } from './directories' ;
15- import { downloadFile } from './downloads' ;
16- import { type PackageKind , SUPPORTED_PACKAGES } from './packages' ;
17- import { getLatestRelease , getLatestReleaseKindByKind } from './releases' ;
185import { SUPPORTED_TESTS } from './tests/types' ;
196import { type SmokeTestsContext } from './context' ;
20-
21- import { installMacDMG } from './installers/mac-dmg' ;
22- import { installMacZIP } from './installers/mac-zip' ;
23- import { installWindowsZIP } from './installers/windows-zip' ;
24- import { installWindowsMSI } from './installers/windows-msi' ;
25-
7+ import { SUPPORTED_PACKAGES } from './packages' ;
268import { testTimeToFirstQuery } from './tests/time-to-first-query' ;
279import { testAutoUpdateFrom } from './tests/auto-update-from' ;
2810import { testAutoUpdateTo } from './tests/auto-update-to' ;
@@ -118,74 +100,10 @@ const argv = yargs(hideBin(process.argv))
118100 } )
119101 . default ( 'tests' , SUPPORTED_TESTS . slice ( ) ) ;
120102
121- type TestSubject = PackageDetails & {
122- filepath : string ;
123- /**
124- * Is the package unsigned?
125- * In which case we'll expect auto-updating to fail.
126- */
127- unsigned ?: boolean ;
128- } ;
129-
130- /**
131- * Either finds the local package or downloads the package
132- */
133- async function getTestSubject (
134- context : SmokeTestsContext
135- ) : Promise < TestSubject > {
136- if ( context . localPackage ) {
137- const compassDistPath = path . resolve (
138- __dirname ,
139- '../../packages/compass/dist'
140- ) ;
141- const buildInfoPath = path . resolve ( compassDistPath , 'target.json' ) ;
142- assert (
143- fs . existsSync ( buildInfoPath ) ,
144- `Expected '${ buildInfoPath } ' to exist`
145- ) ;
146- const details = readPackageDetails ( context . package , buildInfoPath ) ;
147- return {
148- ...details ,
149- filepath : path . resolve ( compassDistPath , details . filename ) ,
150- unsigned : true ,
151- } ;
152- } else {
153- assert (
154- context . bucketName !== undefined && context . bucketKeyPrefix !== undefined ,
155- 'Bucket name and key prefix are needed to download'
156- ) ;
157- const details = writeAndReadPackageDetails ( context ) ;
158- const filepath = await downloadFile ( {
159- url : `https://${ context . bucketName } .s3.amazonaws.com/${ context . bucketKeyPrefix } /${ details . filename } ` ,
160- targetFilename : details . filename ,
161- clearCache : context . forceDownload ,
162- } ) ;
163-
164- return { ...details , filepath } ;
165- }
166- }
167-
168- function getInstaller ( kind : PackageKind ) {
169- if ( kind === 'osx_dmg' ) {
170- return installMacDMG ;
171- } else if ( kind === 'osx_zip' ) {
172- return installMacZIP ;
173- } else if ( kind === 'windows_zip' ) {
174- return installWindowsZIP ;
175- } else if ( kind === 'windows_msi' ) {
176- return installWindowsMSI ;
177- } else {
178- throw new Error ( `Installer for '${ kind } ' is not yet implemented` ) ;
179- }
180- }
181-
182103async function run ( ) {
183- const context : SmokeTestsContext = {
184- ...argv . parseSync ( ) ,
185- sandboxPath : createSandbox ( ) ,
186- } ;
104+ const context : SmokeTestsContext = argv . parseSync ( ) ;
187105
188- console . log ( `Running tests in ${ context . sandboxPath } ` ) ;
106+ console . log ( `Running tests` ) ;
189107
190108 console . log (
191109 'context' ,
@@ -200,81 +118,15 @@ async function run() {
200118 ] )
201119 ) ;
202120
203- const {
204- kind,
205- appName,
206- filepath,
207- buildInfo : { channel, version } ,
208- autoUpdatable,
209- } = await getTestSubject ( context ) ;
210-
211- try {
212- if ( context . tests . length === 0 ) {
213- console . log ( 'Warning: not performing any tests. Pass --tests.' ) ;
214- }
215-
216- for ( const testName of context . tests ) {
217- const installerPath =
218- testName === 'auto-update-to'
219- ? await getLatestRelease (
220- channel ,
221- context . arch ,
222- kind ,
223- context . forceDownload
224- )
225- : filepath ;
121+ for ( const testName of context . tests ) {
122+ console . log ( testName ) ;
226123
227- const install = getInstaller (
228- testName === 'auto-update-to' ? getLatestReleaseKindByKind ( kind ) : kind
229- ) ;
230-
231- const { appPath, uninstall } = install ( {
232- appName,
233- filepath : installerPath ,
234- destinationPath : context . sandboxPath ,
235- } ) ;
236-
237- try {
238- if ( testName === 'time-to-first-query' ) {
239- // Auto-update does not work on mac in CI at the moment. So in that case
240- // we just run the E2E tests to make sure the app at least starts up.
241- testTimeToFirstQuery ( {
242- appName,
243- appPath,
244- } ) ;
245- }
246- if ( testName === 'auto-update-from' ) {
247- await testAutoUpdateFrom ( {
248- appName,
249- appPath,
250- autoUpdatable,
251- } ) ;
252- }
253- if ( testName === 'auto-update-to' ) {
254- assert (
255- context . bucketKeyPrefix !== undefined ,
256- 'Bucket key prefix is needed to download'
257- ) ;
258-
259- await testAutoUpdateTo ( {
260- appName,
261- appPath,
262- autoUpdatable,
263- channel,
264- bucketKeyPrefix : context . bucketKeyPrefix ,
265- version,
266- } ) ;
267- }
268- } finally {
269- await uninstall ( ) ;
270- }
271- }
272- } finally {
273- if ( context . skipCleanup ) {
274- console . log ( `Skipped cleaning up sandbox: ${ context . sandboxPath } ` ) ;
275- } else {
276- console . log ( `Cleaning up sandbox: ${ context . sandboxPath } ` ) ;
277- fs . rmSync ( context . sandboxPath , { recursive : true } ) ;
124+ if ( testName === 'time-to-first-query' ) {
125+ await testTimeToFirstQuery ( context ) ;
126+ } else if ( testName === 'auto-update-from' ) {
127+ await testAutoUpdateFrom ( context ) ;
128+ } else if ( testName === 'auto-update-to' ) {
129+ await testAutoUpdateTo ( context ) ;
278130 }
279131 }
280132}
0 commit comments