diff --git a/lib/download.ts b/lib/download.ts index df77dc08..f9e3e5cd 100644 --- a/lib/download.ts +++ b/lib/download.ts @@ -29,13 +29,20 @@ async function isValidVersion(version: string) { return version === 'insiders' || validVersions.indexOf(version) !== -1; } +/** + * Adapted from https://github.com/microsoft/TypeScript/issues/29729 + * Since `string | 'foo'` doesn't offer auto completion + */ +type StringLiteralUnion = T | (U & {}); +export type DownloadVersion = StringLiteralUnion<'insiders'>; + /** * Download a copy of VS Code archive to `.vscode-test`. * * @param version The version of VS Code to download such as '1.32.0'. You can also use * 'insiders' for downloading latest Insiders. */ -async function downloadVSCodeArchive(version: string): Promise { +async function downloadVSCodeArchive(version: DownloadVersion): Promise { if (!fs.existsSync(vscodeTestDir)) { fs.mkdirSync(vscodeTestDir); } diff --git a/lib/runTest.ts b/lib/runTest.ts index 3418c073..631af342 100644 --- a/lib/runTest.ts +++ b/lib/runTest.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as cp from 'child_process'; -import { downloadAndUnzipVSCode } from './download'; +import { downloadAndUnzipVSCode, DownloadVersion } from './download'; export interface TestOptions { /** @@ -22,7 +22,7 @@ export interface TestOptions { * * Defaults to latest stable version. */ - version?: string; + version?: DownloadVersion; /** * Absolute path to the extension root. Passed to `--extensionDevelopmentPath`. @@ -98,19 +98,19 @@ async function innerRunTests( const fullEnv = Object.assign({}, process.env, testRunnerEnv); const cmd = cp.spawn(executable, args, { env: fullEnv }); - cmd.stdout.on('data', function(data) { + cmd.stdout.on('data', function (data) { console.log(data.toString()); }); - cmd.stderr.on('data', function(data) { + cmd.stderr.on('data', function (data) { console.error(data.toString()); }); - cmd.on('error', function(data) { + cmd.on('error', function (data) { console.log('Test error: ' + data.toString()); }); - cmd.on('close', function(code) { + cmd.on('close', function (code) { console.log(`Exit code: ${code}`); if (code !== 0) {