Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions packages/compass-e2e-tests/smoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,47 @@ import {
assertCommonBuildInfo,
} from './helpers/buildinfo';

const SUPPORTED_PLATFORMS = ['win32', 'darwin', 'linux'] as const;
const SUPPORTED_ARCHS = ['x64', 'arm64'] as const;

function isSupportedPlatform(
value: unknown
): value is typeof SUPPORTED_PLATFORMS[number] {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
return SUPPORTED_PLATFORMS.includes(value as any);
}

function isSupportedArch(
value: unknown
): value is typeof SUPPORTED_ARCHS[number] {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
return SUPPORTED_ARCHS.includes(value as any);
}

function getDefaultPlatform() {
const {
platform,
env: { PLATFORM },
} = process;
if (isSupportedPlatform(PLATFORM)) {
return PLATFORM;
} else if (isSupportedPlatform(platform)) {
return platform;
}
}

function getDefaultArch() {
const {
arch,
env: { ARCH },
} = process;
if (isSupportedArch(ARCH)) {
return ARCH;
} else if (isSupportedArch(arch)) {
return arch;
}
}

const argv = yargs(hideBin(process.argv))
.scriptName('smoke-tests')
.detectLocale(false)
Expand All @@ -42,16 +83,14 @@ const argv = yargs(hideBin(process.argv))
'Will be read from packages/compass/package.json if not specified',
})
.option('platform', {
type: 'string',
choices: ['win32', 'darwin', 'linux'],
choices: SUPPORTED_PLATFORMS,
demandOption: true,
default: process.env.PLATFORM ?? process.platform,
default: getDefaultPlatform(),
})
.option('arch', {
type: 'string',
choices: ['x64', 'arm64'],
choices: SUPPORTED_ARCHS,
demandOption: true,
default: process.env.ARCH ?? process.arch,
default: getDefaultArch(),
})
.option('package', {
type: 'string',
Expand All @@ -65,7 +104,7 @@ const argv = yargs(hideBin(process.argv))
'linux_tar',
'linux_rpm',
'rhel_tar',
],
] as const,
demandOption: true,
description: 'Which package to test',
})
Expand Down Expand Up @@ -122,9 +161,7 @@ async function readPackageVersion(packagePath: string) {
}

async function run() {
const parsedArgs = argv.parseSync();

const context = parsedArgs as SmokeTestsContext;
const context: SmokeTestsContext = argv.parseSync();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would have either used satisfies here (but our prettier's typescript parser needs an update to support that) or simply deleted the type now that it matches the expected type.

Suggested change
const context: SmokeTestsContext = argv.parseSync();
const context = argv.parseSync() satisfies SmokeTestsContext;


console.log(
'context',
Expand Down
Loading