diff --git a/packages/compass-e2e-tests/helpers/smoke-test/build-info.ts b/packages/compass-e2e-tests/helpers/smoke-test/build-info.ts index 08b34344924..9e858b5aba2 100644 --- a/packages/compass-e2e-tests/helpers/smoke-test/build-info.ts +++ b/packages/compass-e2e-tests/helpers/smoke-test/build-info.ts @@ -92,6 +92,7 @@ export function assertBuildInfoIsRHEL( export type PackageDetails = { kind: PackageKind; filename: string; + autoUpdatable: boolean; } & ( | { kind: 'windows_setup' | 'windows_msi' | 'windows_zip'; @@ -124,16 +125,36 @@ export function getPackageDetails( kind === 'windows_zip' ) { assertBuildInfoIsWindows(buildInfo); - return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] }; + return { + kind, + buildInfo, + filename: buildInfo[`${kind}_filename`], + autoUpdatable: kind === 'windows_setup', + }; } else if (kind === 'osx_dmg' || kind === 'osx_zip') { assertBuildInfoIsOSX(buildInfo); - return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] }; + return { + kind, + buildInfo, + filename: buildInfo[`${kind}_filename`], + autoUpdatable: true, + }; } else if (kind === 'linux_deb' || kind === 'linux_tar') { assertBuildInfoIsUbuntu(buildInfo); - return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] }; + return { + kind, + buildInfo, + filename: buildInfo[`${kind}_filename`], + autoUpdatable: false, + }; } else if (kind === 'linux_rpm' || kind === 'rhel_tar') { assertBuildInfoIsRHEL(buildInfo); - return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] }; + return { + kind, + buildInfo, + filename: buildInfo[`${kind}_filename`], + autoUpdatable: false, + }; } else { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new Error(`Unsupported package kind: ${kind}`); diff --git a/packages/compass-e2e-tests/smoke-test.ts b/packages/compass-e2e-tests/smoke-test.ts index d57b14feaa5..9ee64ce7cde 100755 --- a/packages/compass-e2e-tests/smoke-test.ts +++ b/packages/compass-e2e-tests/smoke-test.ts @@ -15,7 +15,10 @@ import { } from './helpers/smoke-test/build-info'; import { createSandbox } from './helpers/smoke-test/directories'; import { downloadFile } from './helpers/smoke-test/downloads'; -import { SUPPORTED_PACKAGES } from './helpers/smoke-test/packages'; +import { + type PackageKind, + SUPPORTED_PACKAGES, +} from './helpers/smoke-test/packages'; import { type SmokeTestsContext } from './helpers/smoke-test/context'; import { installMacZIP } from './installers/mac-zip'; @@ -98,7 +101,14 @@ const argv = yargs(hideBin(process.argv)) description: 'Use the local package instead of downloading', }); -type TestSubject = PackageDetails & { filepath: string }; +type TestSubject = PackageDetails & { + filepath: string; + /** + * Is the package unsigned? + * In which case we'll expect auto-updating to fail. + */ + unsigned?: boolean; +}; /** * Either finds the local package or downloads the package @@ -120,6 +130,7 @@ async function getTestSubject( return { ...details, filepath: path.resolve(compassDistPath, details.filename), + unsigned: true, }; } else { assert( @@ -137,6 +148,16 @@ async function getTestSubject( } } +function getInstaller(kind: PackageKind) { + if (kind === 'osx_dmg') { + return installMacDMG; + } else if (kind === 'osx_zip') { + return installMacZIP; + } else { + throw new Error(`Installer for '${kind}' is not yet implemented`); + } +} + async function run() { const context: SmokeTestsContext = { ...argv.parseSync(), @@ -157,43 +178,26 @@ async function run() { ]) ); - const cleanups: (() => void | Promise)[] = [ - () => { - console.log('Cleaning up sandbox'); - fs.rmSync(context.sandboxPath, { recursive: true }); - }, - ]; const { kind, buildInfo, filepath } = await getTestSubject(context); + const install = getInstaller(kind); try { const appName = buildInfo.productName; - if (kind === 'osx_dmg') { - const { appPath, uninstall } = installMacDMG({ - appName, - filepath, - destinationPath: context.sandboxPath, - }); - cleanups.push(uninstall); - runTest({ appName, appPath }); - } else if (kind === 'osx_zip') { - const { appPath, uninstall } = installMacZIP({ - appName, - filepath, - destinationPath: context.sandboxPath, - }); - cleanups.push(uninstall); + const { appPath, uninstall } = install({ + appName, + filepath, + destinationPath: context.sandboxPath, + }); + try { runTest({ appName, appPath }); - } else { - throw new Error(`Testing '${kind}' packages is not yet implemented`); + } finally { + await uninstall(); } } finally { - // Chain the cleanup functions in reverse order - await cleanups - .slice() - .reverse() - .reduce((previous, cleanup) => previous.then(cleanup), Promise.resolve()); + console.log('Cleaning up sandbox'); + fs.rmSync(context.sandboxPath, { recursive: true }); } }