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 10 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
71 changes: 71 additions & 0 deletions lib/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* 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 '@pkgjs/parseargs';
remcohaszing marked this conversation as resolved.
Show resolved Hide resolved
import { runTests } from './runTest';

const options = {
'vscode-executable-path': { type: 'string' },
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' },
'help': { type: 'boolean' },
} as const;

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

Options
--vscode-executable-path The VS Code executable path used for testing.
--version The VS Code version to download.
Copy link
Author

Choose a reason for hiding this comment

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

This flag is a bit weird IMO. --version usually prints the version of a tool, but in this case it matches the version option of runTests. Any suggestions?

Choose a reason for hiding this comment

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

I would probably rename it to --vscode-version. PS: I'm not a maintainer.

Copy link
Author

Choose a reason for hiding this comment

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

I agree. I’m glad to see someone mention this, regardless whether you’re a maintainer or not. :)

I changed it to --vscode-version, and repurposed the --version flag to print version information.

--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.
--help Show this help message.
`;

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.positionals.length !== 1) {
console.log(help);
return 1;
}

return runTests({
vscodeExecutablePath: parsed.values['vscode-executable-path'],
version: parsed.values.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;
});
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@
]
},
"main": "./out/index.js",
"bin": {
"code-test": "./out/bin.js"
},
"engines": {
"node": ">=16"
},
"dependencies": {
"@pkgjs/parseargs": "^0.10.0",
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"jszip": "^3.10.1",
"semver": "^7.3.8"
},
"devDependencies": {
"@types/node": "^18",
"@types/pkgjs__parseargs": "^0.10.0",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "^4.13.0",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"@nodelib/fs.scandir" "2.1.4"
fastq "^1.6.0"

"@pkgjs/parseargs@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.10.0.tgz#02605e33f8bc4d76efae9b660edc67902f9a0396"
integrity sha512-gcLFrTC3mgIWeDk+eJySEz9unk8XNKi0i2lyppi36qOrW54wBEtOVdGle71ssm5E+vauNwyGKQuWJ2psgTYRVQ==

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz"
Expand Down Expand Up @@ -111,6 +116,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-18.11.10.tgz"
integrity sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==

"@types/pkgjs__parseargs@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@types/pkgjs__parseargs/-/pkgjs__parseargs-0.10.0.tgz#730ffc04dc07359814dc53ede0114aed2f09ae82"
integrity sha512-r+RVVyOIM7MKzUcqySfA19WanRBqMwhcIc30b88SirlJSni31JAxrZq/5u2QCOVp/QACJQefXHTPJGYQH5mqjA==

"@types/rimraf@^3.0.0":
version "3.0.0"
resolved "https://registry.npmjs.org/@types/rimraf/-/rimraf-3.0.0.tgz"
Expand Down