From e2b258341cbc1a5f18902850392e99ca5b00f339 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Thu, 18 Jan 2024 10:46:31 -0800 Subject: [PATCH 1/5] Update Packages --- package-lock.json | 241 ++++++++++++++++++++++++++++++++++++---------- package.json | 10 +- 2 files changed, 198 insertions(+), 53 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60f22c2c74..b9edd25c7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,9 +32,11 @@ "@typescript-eslint/parser": "6.18.0", "@ungap/structured-clone": "1.2.0", "@vscode/debugprotocol": "1.64.0", - "@vscode/test-electron": "2.3.9", + "@vscode/test-cli": "0.0.4", + "@vscode/test-electron": "2.3.8", "@vscode/vsce": "2.22.0", "esbuild": "0.19.11", + "esbuild-register": "3.5.0", "eslint": "8.56.0", "eslint-plugin-header": "3.1.1", "glob": "10.3.10", @@ -44,7 +46,6 @@ "mock-fs": "5.2.0", "rewire": "7.0.0", "sinon": "17.0.1", - "source-map-support": "0.5.21", "typescript": "5.3.3" }, "engines": { @@ -1191,6 +1192,101 @@ "vscode": "^1.75.0" } }, + "node_modules/@vscode/test-cli": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.4.tgz", + "integrity": "sha512-Tx0tfbxeSb2Xlo+jpd+GJrNLgKQHobhRHrYvOipZRZQYWZ82sKiK02VY09UjU1Czc/YnZnqyAnjUfaVGl3h09w==", + "dev": true, + "dependencies": { + "@types/mocha": "^10.0.2", + "chokidar": "^3.5.3", + "glob": "^10.3.10", + "minimatch": "^9.0.3", + "mocha": "^10.2.0", + "supports-color": "^9.4.0", + "yargs": "^17.7.2" + }, + "bin": { + "vscode-test": "out/bin.mjs" + } + }, + "node_modules/@vscode/test-cli/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@vscode/test-cli/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@vscode/test-cli/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@vscode/test-cli/node_modules/supports-color": { + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.4.0.tgz", + "integrity": "sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/@vscode/test-cli/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@vscode/test-cli/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/@vscode/test-electron": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.9.tgz", @@ -1501,12 +1597,6 @@ "node": "*" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true - }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -1980,6 +2070,18 @@ "@esbuild/win32-x64": "0.19.11" } }, + "node_modules/esbuild-register": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/esbuild-register/-/esbuild-register-3.5.0.tgz", + "integrity": "sha512-+4G/XmakeBAsvJuDugJvtyF1x+XJT4FMocynNpxrvEBViirpfUn2PgNpCHedfWhF4WokNsO/OvMKrmJOIJsI5A==", + "dev": true, + "dependencies": { + "debug": "^4.3.4" + }, + "peerDependencies": { + "esbuild": ">=0.12 <1" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -4226,25 +4328,6 @@ "node": ">=8" } }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "node_modules/split": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", @@ -5644,6 +5727,79 @@ "@microsoft/applicationinsights-web-basic": "^3.0.6" } }, + "@vscode/test-cli": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@vscode/test-cli/-/test-cli-0.0.4.tgz", + "integrity": "sha512-Tx0tfbxeSb2Xlo+jpd+GJrNLgKQHobhRHrYvOipZRZQYWZ82sKiK02VY09UjU1Czc/YnZnqyAnjUfaVGl3h09w==", + "dev": true, + "requires": { + "@types/mocha": "^10.0.2", + "chokidar": "^3.5.3", + "glob": "^10.3.10", + "minimatch": "^9.0.3", + "mocha": "^10.2.0", + "supports-color": "^9.4.0", + "yargs": "^17.7.2" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + } + }, + "minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "supports-color": { + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-9.4.0.tgz", + "integrity": "sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw==", + "dev": true + }, + "yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "requires": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + } + }, + "yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true + } + } + }, "@vscode/test-electron": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.9.tgz", @@ -5872,12 +6028,6 @@ "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", "dev": true }, - "buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true - }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -6228,6 +6378,15 @@ "@esbuild/win32-x64": "0.19.11" } }, + "esbuild-register": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/esbuild-register/-/esbuild-register-3.5.0.tgz", + "integrity": "sha512-+4G/XmakeBAsvJuDugJvtyF1x+XJT4FMocynNpxrvEBViirpfUn2PgNpCHedfWhF4WokNsO/OvMKrmJOIJsI5A==", + "dev": true, + "requires": { + "debug": "^4.3.4" + } + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -7898,22 +8057,6 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "split": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", diff --git a/package.json b/package.json index 2577d897b8..b7eca4065a 100644 --- a/package.json +++ b/package.json @@ -97,9 +97,11 @@ "@typescript-eslint/parser": "6.18.0", "@ungap/structured-clone": "1.2.0", "@vscode/debugprotocol": "1.64.0", + "@vscode/test-cli": "0.0.4", "@vscode/test-electron": "2.3.9", "@vscode/vsce": "2.22.0", "esbuild": "0.19.11", + "esbuild-register": "3.5.0", "eslint": "8.56.0", "eslint-plugin-header": "3.1.1", "glob": "10.3.10", @@ -109,7 +111,6 @@ "mock-fs": "5.2.0", "rewire": "7.0.0", "sinon": "17.0.1", - "source-map-support": "0.5.21", "typescript": "5.3.3" }, "extensionDependencies": [ @@ -117,12 +118,13 @@ ], "main": "./out/main.js", "scripts": { + "esbuild-base": "esbuild --bundle --platform=node --target=node18.15 --format=cjs --sourcemap --external:mocha --external:vscode --external:eslint", "lint": "eslint . --ext .ts", - "build": "esbuild ./src/main.ts --outdir=out --sourcemap --bundle --external:vscode --platform=node", + "build": "npm run esbuild-base -- src/main.ts --outdir=out", "build-watch": "npm run build -- --watch", - "build-test": "tsc --incremental", + "build-test": "npm run esbuild-base -- test/**/*.test.ts --outdir=out/test --sources-content=false", "build-test-watch": "npm run build-test -- --watch", - "test": "npm run build-test && node ./out/test/runTests.js", + "test": "npm run build-test && vscode-test", "package": "vsce package --no-gitHubIssueLinking", "publish": "vsce publish" }, From e2d7513370321df0ab9d2011b6cf43a40f5c3cd0 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Thu, 18 Jan 2024 10:46:44 -0800 Subject: [PATCH 2/5] Add Extensions --- .vscode/extensions.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000..2cf998b274 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "connor4312.esbuild-problem-matchers", + "hbenl.vscode-mocha-test-adapter", + "ms-vscode.extension-test-runner" + ] +} From 80842b26c4c8ccd002e9352468f10d154ced082c Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Thu, 18 Jan 2024 10:47:25 -0800 Subject: [PATCH 3/5] Add Test Configuration --- .vscode-test.js | 13 +++++ test/runTests.ts | 114 ------------------------------------------ test/runTestsInner.ts | 80 ----------------------------- tsconfig.json | 9 ++-- 4 files changed, 16 insertions(+), 200 deletions(-) create mode 100644 .vscode-test.js delete mode 100644 test/runTests.ts delete mode 100644 test/runTestsInner.ts diff --git a/.vscode-test.js b/.vscode-test.js new file mode 100644 index 0000000000..b8ccc18726 --- /dev/null +++ b/.vscode-test.js @@ -0,0 +1,13 @@ +// .vscode-test.js +const { defineConfig } = require("@vscode/test-cli"); + +module.exports = defineConfig({ + files: "out/test/**/*.test.js", + launchArgs: ["--profile-temp"], + workspaceFolder: "test/TestEnvironment.code-workspace", + mocha: { + ui: "bdd", + timeout: 600000, //10 minutes long to allow for debugging + slow: 2000, + }, +}); diff --git a/test/runTests.ts b/test/runTests.ts deleted file mode 100644 index bfeb87fe20..0000000000 --- a/test/runTests.ts +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// NOTE: This code is borrowed under permission from: -// https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample/src/test - -import * as path from "path"; -import { ConsoleReporter, downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath, runTests } from "@vscode/test-electron"; -import { existsSync } from "fs"; -import { spawnSync } from "child_process"; - -/** This is the main test entrypoint that: - * - Prepares the test environment by downloading a testing instance of vscode and any additional extensions - * - Starts the test environment with runTestsInner injected into the extensionsTestsPath which will in turn start the Mocha test runner inside the environment. - * - * Tools like npm run test and vscode tasks should point to this script to begin the testing process. It is assumed you have built the extension prior to this step, it will error if it does not find the built extension or related test scaffolding. - * */ -async function main(): Promise { - // Verify that the extension is built - const compiledExtensionPath = path.resolve(__dirname, "../main.js"); - if (!existsSync(compiledExtensionPath)) { - console.error("ERROR: The extension is not built yet. Please run a build first, using either the 'Run Build Task' in VSCode or ./build.ps1 in PowerShell."); - process.exit(1); - } - - try { - /** The folder containing the Extension Manifest package.json. Passed to `--extensionDevelopmentPath */ - const extensionDevelopmentPath = path.resolve(__dirname, "../../"); - - /** The path to the test script that will run inside the vscode instance. Passed to --extensionTestsPath */ - const extensionTestsPath = path.resolve(__dirname, "./runTestsInner"); - - /** The starting workspace/folder to open in vscode. By default this is a testing instance pointed to the Examples folder */ - const workspacePath = process.env.__TEST_WORKSPACE_PATH ?? "test/TestEnvironment.code-workspace"; - const workspaceToOpen = path.resolve(extensionDevelopmentPath, workspacePath); - - /** The version to test. By default we test on insiders. */ - const vsCodeVersion = process.env.__TEST_VSCODE_VERSION ?? "insiders"; - - /** Install a temporary vscode. This must be done ahead of RunTests in order to install extensions ahead of time. @see https://github.com/microsoft/vscode-test/blob/addc23e100b744de598220adbbf0761da870eda9/README.md?plain=1#L71-L89 **/ - const testVSCodePath = await downloadAndUnzipVSCode(vsCodeVersion, undefined, new ConsoleReporter(true)); - InstallExtension(testVSCodePath, "ms-dotnettools.csharp"); - - const launchArgs = [ - workspaceToOpen - ]; - - /** This is fed to runTestsInner so it knows the extension context to find config files */ - const extensionTestsEnv: Record = { - __TEST_EXTENSION_DEVELOPMENT_PATH: extensionDevelopmentPath - }; - - // This info is provided by the Mocha test explorer so it can communicate with the mocha running inside the vscode test instance. - // Adapted from: https://github.com/hbenl/mocha-explorer-launcher-scripts/blob/bd3ace403e729de1be31f46afddccc477f82a178/vscode-test/index.ts#L33-L37 - if (process.argv[2]) { - const mochaIPCInfo = JSON.parse(process.argv[2]); - extensionTestsEnv.MOCHA_WORKER_IPC_ROLE = mochaIPCInfo.role; - extensionTestsEnv.MOCHA_WORKER_IPC_HOST = mochaIPCInfo.host; - extensionTestsEnv.MOCHA_WORKER_IPC_PORT = String(mochaIPCInfo.port); - } - - /** This env var should be passed by launch configurations for debugging the extension tests. If specified, we should wait for it to connect because it means something explicitly asked for debugging **/ - const debugPort = process.env.__TEST_DEBUG_INSPECT_PORT; - console.log("DebugPort", debugPort); - if (debugPort !== undefined) { - console.log(`__TEST_DEBUG_INSPECT_PORT is set to ${debugPort}`); - launchArgs.push(`--inspect-brk-extensions=${debugPort}`); - } else { - // Make debugger optionally available. Mocha Test adapter will use this when debugging because it provides no indicator when it is debugging vs. just running - // FIXME: Because the mocha test explorer often doesn't attach until after the tests start and it provides no indicator of debug vs run, it may be flaky for debug until https://github.com/hbenl/vscode-mocha-test-adapter/pull/240 is merged. To workaround, start debugging sessions using "Test Extensions" launch config. We could use a timeout here but it would slow down everything including normal runs. - launchArgs.push("--inspect-extensions=59229"); - } - - // Download VS Code, unzip it and run the integration test - await runTests({ - extensionDevelopmentPath, - extensionTestsPath, - launchArgs: launchArgs, - // This is necessary because the tests fail if more than once - // instance of Code is running. - version: vsCodeVersion, - extensionTestsEnv: extensionTestsEnv - }); - } catch (err) { - console.error(`RunTests failed to run tests: ${err}`); - process.exit(1); - } finally { - // Clean this up because runTests sets it on the current process, not the child one. - process.env.__TEST_DEBUG_INSPECT_PORT = undefined; - } -} - -/** Installs an extension into an existing vscode instance. Returns the output result */ -function InstallExtension(vscodeExePath: string, extensionIdOrVSIXPath: string): string { - // Install the csharp extension which is required for the dotnet debugger testing - const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExePath); - - args.push("--install-extension", extensionIdOrVSIXPath); - - // Install the extension. There is no API for this, we must use the executable. This is the recommended sample in the vscode-test repo. - console.log(`Installing extension: ${cli} ${args.join(" ")}`); - const installResult = spawnSync(cli, args, { - encoding: "utf8", - stdio: "inherit" - }); - - if (installResult.status !== 0) { - console.error(installResult.stderr); - throw new Error(`Failed to install extension: ${installResult.stderr}`); - } - return installResult.stdout; -} - -void main(); diff --git a/test/runTestsInner.ts b/test/runTestsInner.ts deleted file mode 100644 index 8ece590a71..0000000000 --- a/test/runTestsInner.ts +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { globSync } from "glob"; -import path from "path"; -import Mocha from "mocha"; -/** This is the entrypoint into the standalone vscode instance that should be passed to the --extensionsTestPath parameter of the test VSCode instance. */ -export function run(testsRoot: string): Promise { - return runTestsInner(testsRoot); -} - -/** Runs inside of the test vscode instance, and should set up and activate the test runner */ -function runTestsInner(testsRoot: string): Promise { - // Allow tools like Mocha Test Explorer to inject their own Mocha worker - if (process.env.MOCHA_WORKER_PATH) { - return require(process.env.MOCHA_WORKER_PATH); - } - - console.log(`\n\n=====\nTest Runner START\n${testsRoot}\n=====`); - - /** Passed from RunTests */ - const rootDir = process.env.__TEST_EXTENSION_DEVELOPMENT_PATH; - if (!rootDir) { - throw new Error("Missing environment variable __TEST_EXTENSIONDEVELOPMENTPATH, this is probably a bug in runTests.ts"); - } - - interface MochaOptionsWithFiles extends Mocha.MochaOptions { - spec?: string; - } - - // eslint-disable-next-line @typescript-eslint/no-var-requires - const config: MochaOptionsWithFiles = require(path.resolve(rootDir, ".mocharc.json")); - if (config.spec === undefined) { - throw new Error("spec must be specified in the config options when running vscode launch tests"); - } - - const mocha = new Mocha(config); - // if (process.env.TF_BUILD) { - // console.log("Detected Azure DevOps, disabling color output as ANSI escapes do not make Azure Devops happy."); - // config.color = false; - // } - - // Test if files is empty - const files = globSync(config.spec, { cwd: rootDir }); - if (files.length === 0) { - console.log("No tests found for glob pattern: test.ts in directory: " + rootDir); - throw new Error("No tests found for glob pattern: test.ts in directory: " + rootDir); - } - - // Add files to the test suite - for (const file of files) { - const testFile = path.resolve(rootDir, file); - mocha.addFile(testFile); - } - - mocha.reporter("mocha-multi-reporters", { - reporterEnabled: "spec, xunit", - xunitReporterOptions: { - output: path.resolve(rootDir, "test-results.xml"), - } - }); - - return new Promise((c, e) => { - try { - mocha.run(failures => { - console.log(`Mocha Run Finished with ${failures} failures.`); - if (failures > 0) { - throw new Error(`${failures} tests failed.`); - } else { - console.log("\n\n=====\nTest Runner STOP\n====="); - c(); - return; - } - }); - } catch (err) { - console.error("Failed to run tests"); - e(err); - } - }); -} diff --git a/tsconfig.json b/tsconfig.json index ee41a6622d..482429bcc6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,12 +5,8 @@ "module": "commonjs", "outDir": "out", "target": "ES2022", - "lib": [ - "ES2022", - "DOM" - ], + "lib": ["ES2022"], "sourceMap": true, - "rootDir": ".", "strict": true, "noFallthroughCasesInSwitch": true, "noImplicitOverride": true, @@ -19,7 +15,8 @@ "noUnusedParameters": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, - "useUnknownInCatchVariables": true + "useUnknownInCatchVariables": true, + "types": ["node", "mocha", "sinon"] }, "include": [ "src", "test" ], "exclude": [ "node_modules/@ungap/structured-clone" ] From 6ca40b03e37a0b390bd8f1bc6f231971367bc1ca Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Mon, 22 Jan 2024 11:09:01 -0800 Subject: [PATCH 4/5] Simplify launch configs and suppress messages in example environment for first runs --- .vscode/launch.json | 82 ++++++---------------------------- examples/.vscode/settings.json | 3 ++ 2 files changed, 17 insertions(+), 68 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c1b8d2d443..2aea0676dd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,22 +9,8 @@ "request": "launch", "runtimeExecutable": "${execPath}", "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "env": { - "__TEST_WORKSPACE_PATH": "${workspaceFolder}/examples", - }, - "sourceMaps": true, - // This speeds up source map detection and makes smartStep work correctly - "outFiles": [ - "${workspaceFolder}/out/**/*.js", - "!**/node_modules/**", - "!**/.vscode-test/**" - ], - "skipFiles": [ - "/**", - "**/node_modules/**", - "**/.vscode-test/**" + "--extensionDevelopmentPath=${workspaceFolder}", + "${workspaceFolder}/examples" ], "presentation": { "hidden": false, @@ -35,6 +21,7 @@ { // Runs the extension in an empty temp profile that is automatically cleaned up after use // Undocumented: https://github.com/microsoft/vscode-docs/issues/6220 + // BUG: Breakpoints will not work with temp profile currently "name": "Launch Extension - Temp Profile", "type": "extensionHost", "request": "launch", @@ -44,18 +31,20 @@ "--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/examples" ], - "sourceMaps": true, - // This speeds up source map detection and makes smartStep work correctly - "outFiles": [ - "${workspaceFolder}/out/**/*.js", + "resolveSourceMapLocations": [ + "${workspaceFolder}/**", "!**/node_modules/**", "!**/.vscode-test/**" ], - "skipFiles": [ - "/**", - "**/node_modules/**", - "**/.vscode-test/**" - ], + "outFiles": ["${workspaceFolder}/**/*.js", "!**/node_modules/**"], + "sourceMapRenames": true, + "sourceMaps": true, + // This speeds up source map detection and makes smartStep work correctly + // "skipFiles": [ + // "/**", + // "**/node_modules/**", + // "**/.vscode-test/**" + // ], "presentation": { "hidden": false, "group": "test", @@ -74,54 +63,11 @@ "--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/examples" ], - "sourceMaps": true, - // This speeds up source map detection and makes smartStep work correctly - "outFiles": [ - "${workspaceFolder}/out/**/*.js", - "!**/node_modules/**", - "!**/.vscode-test/**" - ], - "skipFiles": [ - "/**", - "**/node_modules/**", - "**/.vscode-test/**" - ], "presentation": { "hidden": false, "group": "test", "order": 2 } - }, - { - "name": "Test Extension", - "type": "node", - "request": "launch", - "program": "${workspaceFolder}/out/test/runTests.js", - "cascadeTerminateToConfigurations": [ - "ExtensionTests", - ], - // This speeds up source map detection and makes smartStep work correctly - "outFiles": [ - "${workspaceFolder}/out/**/*.js", - "!**/node_modules/**", - "!**/.vscode-test/**" - ], - "skipFiles": [ - "/**", - "**/node_modules/**", - "**/.vscode-test/**" - ], - "attachSimplePort": 59229, // THe default is 9229 but we want to avoid conflicts because we will have two vscode instances running. - "env": { - "__TEST_DEBUG_INSPECT_PORT": "59229" // Needs to match attachSimplePort - }, - "presentation": { - "hidden": false, - }, - "internalConsoleOptions": "neverOpen", - "console": "integratedTerminal", - "autoAttachChildProcesses": false, - "preLaunchTask": "test-watch" } ] } diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index a37044b519..0563b1d704 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -3,4 +3,7 @@ // Relative paths for this setting are always relative to the workspace root dir. "powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1", "files.defaultLanguage": "powershell", + "git.openRepositoryInParentFolders": "never", + "csharp.suppressDotnetRestoreNotification": true, + "extensions.ignoreRecommendations": true } From 4fdfa2fd2a7d56964381545d08fd8832a0814d7d Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Tue, 23 Jan 2024 16:19:12 -0800 Subject: [PATCH 5/5] Switch back to tsc for test builds --- .vscode/extensions.json | 8 ----- .vscode/launch.json | 23 +++++++++++-- extension-dev.code-workspace | 65 +++++++++--------------------------- package.json | 6 ++-- 4 files changed, 39 insertions(+), 63 deletions(-) delete mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 2cf998b274..0000000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "recommendations": [ - "dbaeumer.vscode-eslint", - "connor4312.esbuild-problem-matchers", - "hbenl.vscode-mocha-test-adapter", - "ms-vscode.extension-test-runner" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json index 2aea0676dd..a2746ed1ee 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,7 +16,8 @@ "hidden": false, "group": "test", "order": 2 - } + }, + "preLaunchTask": "build-watch" }, { // Runs the extension in an empty temp profile that is automatically cleaned up after use @@ -49,7 +50,8 @@ "hidden": false, "group": "test", "order": 2 - } + }, + "preLaunchTask": "build-watch" }, { // Runs the extension in an isolated but persistent profile separate from the user settings @@ -67,7 +69,22 @@ "hidden": false, "group": "test", "order": 2 - } + }, + "preLaunchTask": "build-watch" + }, + { + // Runs the extension in an isolated but persistent profile separate from the user settings + // Undocumented: https://github.com/microsoft/vscode-docs/issues/6220 + "name": "Test Extension", + "type": "node-terminal", + "request": "launch", + "command": "npm test", + "presentation": { + "hidden": false, + "group": "test", + "order": 2 + }, + "preLaunchTask": "test-watch" } ] } diff --git a/extension-dev.code-workspace b/extension-dev.code-workspace index 73b8f8e4c6..deebe2a386 100644 --- a/extension-dev.code-workspace +++ b/extension-dev.code-workspace @@ -11,15 +11,18 @@ ], "extensions": { "recommendations": [ + "connor4312.esbuild-problem-matchers", "davidanson.vscode-markdownlint", "dbaeumer.vscode-eslint", "editorconfig.editorconfig", + "github.vscode-github-actions", + "GitHub.vscode-pull-request-github", + "hbenl.vscode-mocha-test-adapter", "josefpihrt-vscode.roslynator", - "ms-azure-devops.azure-pipelines", "ms-dotnettools.csharp", + "ms-vscode.extension-test-runner", "ms-vscode.powershell", - "hbenl.vscode-mocha-test-adapter", - "connor4312.esbuild-problem-matchers" + "redhat.vscode-yaml" ] }, "settings": { @@ -31,7 +34,7 @@ "files.insertFinalNewline": true, "files.associations": { "**/snippets/*.json": "jsonc", // Use JSONC instead of JSON because that's how VS Code interprets snippet files, and it enables better source documentation. - "**/.vsts-ci/**/*.yml": "azure-pipelines", + "**/.vsts-ci/**/*.yml": "azure-pipelines" }, // Ignore the Markdown rule: "markdownlint.config": { @@ -54,18 +57,7 @@ "editor.formatOnSave": true, "editor.formatOnSaveMode": "modificationsIfAvailable" }, - "mochaExplorer.configFile": ".mocharc.json", - "mochaExplorer.launcherScript": "out/test/runTests", - "mochaExplorer.autoload": false, // The test instance pops up every time discovery or run is done, this could be annoying on startup. - "mochaExplorer.debuggerPort": 59229, // Matches the launch config, we dont want to use the default port as we are launching a duplicate instance of vscode and it might conflict. - "mochaExplorer.ipcRole": "server", - "mochaExplorer.ipcTimeout": 30000, // 30 seconds - "testExplorer.useNativeTesting": true, - "mochaExplorer.env": { - "VSCODE_VERSION": "insiders", - "ELECTRON_RUN_AS_NODE": null - }, - "powershell.cwd": "Client", + "powershell.cwd": "Client" }, "tasks": { "version": "2.0.0", @@ -73,12 +65,7 @@ "options": { "shell": { "executable": "pwsh.exe", - "args": [ - "-NoProfile", - "-ExecutionPolicy", - "Bypass", - "-Command" - ] + "args": ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] } } }, @@ -86,10 +73,7 @@ "options": { "shell": { "executable": "pwsh", - "args": [ - "-NoProfile", - "-Command" - ] + "args": ["-NoProfile", "-Command"] } } }, @@ -97,10 +81,7 @@ "options": { "shell": { "executable": "/usr/local/bin/pwsh", - "args": [ - "-NoProfile", - "-Command" - ] + "args": ["-NoProfile", "-Command"] } } }, @@ -112,10 +93,7 @@ "cwd": "${workspaceFolder:Client}" }, "command": "Invoke-Build Build", - "problemMatcher": [ - "$msCompile", - "$tsc" - ], + "problemMatcher": ["$msCompile", "$tsc"], "group": { "kind": "build", "isDefault": true @@ -128,10 +106,7 @@ "cwd": "${workspaceFolder:Client}" }, "command": "Invoke-Build Test", - "problemMatcher": [ - "$msCompile", - "$tsc" - ], + "problemMatcher": ["$msCompile", "$tsc"], "group": { "kind": "test", "isDefault": true @@ -143,9 +118,7 @@ "options": { "cwd": "${workspaceFolder:Server}" }, - "problemMatcher": [ - "$msCompile" - ], + "problemMatcher": ["$msCompile"], "command": "Invoke-Build TestServerPS72", "group": { "kind": "test", @@ -176,13 +149,7 @@ "type": "pickString", "id": "clientBuildCommand", "description": "Which Invoke-Build Client Task?", - "options": [ - "Restore", - "Clean", - "Build", - "Test", - "Package" - ], + "options": ["Restore", "Clean", "Build", "Test", "Package"], "default": "Clean" }, { @@ -197,7 +164,7 @@ "Test", "TestServer", "TestServerPS72", - "TestE2E", + "TestE2E" ], "default": "Clean" } diff --git a/package.json b/package.json index b7eca4065a..58349de241 100644 --- a/package.json +++ b/package.json @@ -118,11 +118,11 @@ ], "main": "./out/main.js", "scripts": { - "esbuild-base": "esbuild --bundle --platform=node --target=node18.15 --format=cjs --sourcemap --external:mocha --external:vscode --external:eslint", + "esbuild-base": "esbuild --platform=node --target=node18.15 --format=cjs --sourcemap", "lint": "eslint . --ext .ts", - "build": "npm run esbuild-base -- src/main.ts --outdir=out", + "build": "npm run esbuild-base -- --bundle src/main.ts --outdir=out --external:mocha --external:vscode --external:eslint", "build-watch": "npm run build -- --watch", - "build-test": "npm run esbuild-base -- test/**/*.test.ts --outdir=out/test --sources-content=false", + "build-test": "tsc --incremental", "build-test-watch": "npm run build-test -- --watch", "test": "npm run build-test && vscode-test", "package": "vsce package --no-gitHubIssueLinking",