diff --git a/.vscode-test.mjs b/.vscode-test.mjs new file mode 100644 index 000000000..5b8a8ae40 --- /dev/null +++ b/.vscode-test.mjs @@ -0,0 +1,6 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See LICENSE.md in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export { azExtTestConfig as default } from '@microsoft/vscode-azext-eng/vscode-test'; // Other configurations exist diff --git a/package.json b/package.json index 693884a63..ce5359ca8 100644 --- a/package.json +++ b/package.json @@ -454,7 +454,7 @@ "build:check": "tsc --noEmit", "package": "vsce package --githubBranch main", "lint": "eslint --max-warnings 0", - "test": "node ./out/test/runTest.js" + "test": "vscode-test" }, "devDependencies": { "@microsoft/vscode-azext-eng": "file:../vscode-azuretools/eng/microsoft-vscode-azext-eng-1.0.0-alpha.1.tgz", diff --git a/test/index.ts b/test/index.ts deleted file mode 100644 index dcf87474e..000000000 --- a/test/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE.md in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as glob from 'glob'; -import * as Mocha from 'mocha'; -import * as path from 'path'; - -export async function run(): Promise { - const options: Mocha.MochaOptions = { - ui: 'tdd', - color: true, - reporter: 'mocha-multi-reporters', - reporterOptions: { - reporterEnabled: 'spec, mocha-junit-reporter', - mochaJunitReporterReporterOptions: { - mochaFile: path.resolve(__dirname, '..', '..', 'test-results.xml') - } - }, - timeout: 10000 - }; - - addEnvVarsToMochaOptions(options); - console.log(`Mocha options: ${JSON.stringify(options, undefined, 2)}`); - - const mocha = new Mocha(options); - - const files: string[] = await new Promise((resolve, reject) => { - glob('**/**.test.js', { cwd: __dirname }, (err, result) => { - err ? reject(err) : resolve(result); - }); - }); - - files.forEach(f => mocha.addFile(path.resolve(__dirname, f))); - - const failures = await new Promise(resolve => mocha.run(resolve)); - if (failures > 0) { - throw new Error(`${failures} tests failed.`); - } -} - -function addEnvVarsToMochaOptions(options: Mocha.MochaOptions): void { - for (const envVar of Object.keys(process.env)) { - const match: RegExpMatchArray | null = envVar.match(/^mocha_(.+)/i); - if (match) { - const [, option] = match; - let value: string | number = process.env[envVar] || ''; - if (typeof value === 'string' && !isNaN(parseInt(value))) { - value = parseInt(value); - } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (options)[option] = value; - } - } -} diff --git a/test/runTest.ts b/test/runTest.ts deleted file mode 100644 index 04f027d71..000000000 --- a/test/runTest.ts +++ /dev/null @@ -1,46 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE.md in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath, runTests } from '@vscode/test-electron'; -import * as cp from 'child_process'; -import * as path from 'path'; - -async function main(): Promise { - try { - const vscodeExecutablePath = await downloadAndUnzipVSCode('stable'); - const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath); - - cp.spawnSync( - cli, - [ - ...args, - '--install-extension', 'ms-azuretools.vscode-azureresourcegroups', - '--install-extension', 'ms-azuretools.vscode-azurefunctions', - ], - { - encoding: 'utf-8', - stdio: 'inherit' - }); - - const repoRoot: string = path.resolve(__dirname, '..', '..'); - await runTests({ - vscodeExecutablePath, - extensionDevelopmentPath: repoRoot, - launchArgs: [ - path.resolve(repoRoot, 'test', 'test.code-workspace'), - '--disable-workspace-trust' - ], - extensionTestsPath: path.resolve(repoRoot, 'dist', 'test', 'index'), - extensionTestsEnv: { - DEBUGTELEMETRY: 'v' - } - }); - } catch (err) { - console.error('Failed to run tests'); - process.exit(1); - } -} - -main();