Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CLI #161

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 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
86 changes: 86 additions & 0 deletions lib/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { resolve } from 'path';
import { parseArgs } from 'util';
import { runTests } from './runTest';

// TypeScript doesn’t allow imports outside the root dir.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');

const options = {
'vscode-executable-path': { type: 'string' },
'vscode-version': { type: 'string' },
platform: { type: 'string' },
'reuse-machine-install': { type: 'boolean' },
'extension-development-path': { type: 'string', multiple: true },

Choose a reason for hiding this comment

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

Did you intentionally miss this one in help? Also, is it intentionally made "multiple"?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! I accidentally missed that one.

It’s multiple, because runTests() accepts it as an array.

'launch-args': { type: 'string', multiple: true },
'extract-sync': { type: 'boolean' },
version: { type: 'boolean' },
help: { type: 'boolean' },
} as const;

const versionInfo = `${pkg.name} ${pkg.version}`;

const help = `Usage: code-test [options][extension-tests-path...]

Options
--vscode-executable-path The VS Code executable path used for testing.
--vscode-version The VS Code version to download.
--platform The VS Code platform to download. If not specified, it defaults to
the current platform.
--reuse-machine-install Whether VS Code should be launched using default settings and
extensions installed on this machine.
--launch-args A list of launch arguments passed to VS Code executable,
--extract-sync Whether the downloaded zip should be synchronously extracted.
--version Output the version information and exit.
--help Show this help message.

${versionInfo}`;

async function main(): Promise<number> {
let parsed;
try {
parsed = parseArgs({ options, allowPositionals: true });
} catch {
console.log(help);
return 1;
}

if (parsed.values.help) {
console.log(help);
return 0;
}

if (parsed.values.version) {
console.log(versionInfo);
return 0;
}

if (parsed.positionals.length !== 1) {
console.log(help);
return 1;
}

return runTests({
vscodeExecutablePath: parsed.values['vscode-executable-path'],
version: parsed.values['vscode-version'],
platform: parsed.values.platform,
reuseMachineInstall: parsed.values['reuse-machine-install'],
extensionDevelopmentPath: parsed.values['extension-development-path'] || process.cwd(),
extensionTestsPath: resolve(process.cwd(), parsed.positionals[0]),
launchArgs: parsed.values['launch-args'],
extractSync: parsed.values['extract-sync'],
});
}

main()
.catch((error) => {
console.error(error);
return 1;
})
.then((exitCode) => {
process.exitCode = exitCode;
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
]
},
"main": "./out/index.js",
"bin": {
"code-test": "./out/bin.js"
},
"engines": {
"node": ">=16"
},
Expand Down