Skip to content

Commit d73c910

Browse files
authored
🧪 Redesign testing to use vscode-test CLI (#235)
VSCode-required E2E tests and Mocha tests are run separately now based on whether they are in a thing.tests.ts or thing.vscode.tests.ts file.
1 parent 707d6a0 commit d73c910

19 files changed

Lines changed: 177 additions & 858 deletions

.mocharc.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

.mocharc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require: 'esbuild-register'
2+
spec:
3+
- 'src/**/*.test.ts'
4+
- 'test/**/*.test.ts'
5+
ignore: ['**/*.vscode.test.ts']
6+
exit: true
7+
failZero: true
8+
color: true
9+
enable-source-maps: true

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# Dont forget to update this in package.json script esbuild-base too!
12
use-node-version=18.15.0
23
engine-strict=true

.vscode-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// .vscode-test.js
2+
const { defineConfig } = require('@vscode/test-cli')
3+
4+
module.exports = defineConfig({
5+
files: 'dist/test/**/*.vscode.test.js',
6+
launchArgs: ['--profile=vscode-pester-test'],
7+
mocha: {
8+
ui: 'bdd',
9+
timeout: 600000 // 10 minutes to allow for debugging
10+
}
11+
})

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"github.vscode-github-actions",
66
"dbaeumer.vscode-eslint",
77
"connor4312.esbuild-problem-matchers",
8-
"hbenl.vscode-mocha-test-adapter"
8+
"hbenl.vscode-mocha-test-adapter",
9+
"ms-vscode.extension-test-runner"
910
]
1011
}

.vscode/launch.json

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,6 @@
5252
"showAsyncStacks": true,
5353
"smartStep": true,
5454
"preLaunchTask": "build-watch"
55-
},
56-
{
57-
"name": "Test Extension",
58-
"type": "node",
59-
"request": "launch",
60-
"program": "${workspaceFolder}/test/runTests.ts",
61-
"runtimeArgs": ["-r", "@swc-node/register"],
62-
"sourceMaps": true,
63-
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**", "!**/.vscode-test/**"],
64-
"smartStep": true,
65-
"attachSimplePort": 59229, // The default is 9229 but we want to avoid conflicts because we will have two vscode instances running.
66-
"env": {
67-
"__TEST_DEBUG_INSPECT_PORT": "59229" // Needs to match attachSimplePort
68-
},
69-
"presentation": {
70-
"hidden": false,
71-
"group": "_test"
72-
},
73-
"internalConsoleOptions": "neverOpen",
74-
"console": "integratedTerminal",
75-
"autoAttachChildProcesses": false
7655
}
7756
]
7857
}

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"[typescript]": {
77
"editor.defaultFormatter": "vscode.typescript-language-features"
88
},
9-
"mochaExplorer.configFile": ".mocharc.json",
109
"mochaExplorer.logpanel": true,
1110
"testExplorer.useNativeTesting": true,
11+
"extension-test-runner.debugOptions": {
12+
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"]
13+
},
1214
"mochaExplorer.env": {
1315
"VSCODE_VERSION": "insiders",
1416
"ELECTRON_RUN_AS_NODE": null

.vscode/tasks.json

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,39 @@
1010
"type": "npm",
1111
"script": "build-watch",
1212
"group": "build",
13-
"problemMatcher": {
14-
"owner": "typescript",
15-
"source": "rollup",
16-
"pattern": {
17-
"regexp": "^(.*):(\\d+):(\\d+) - (error|warning) TS(\\d+): (.*)$",
18-
"file": 1,
19-
"line": 2,
20-
"column": 3,
21-
"severity": 4,
22-
"code": 5,
23-
"message": 6
24-
},
25-
"severity": "info",
26-
"fileLocation": ["relative", "${workspaceFolder}"],
27-
"background": {
28-
"activeOnStart": true,
29-
"beginsPattern": "^rollup v\\d+\\.\\d+\\.\\d+$",
30-
"endsPattern": {
31-
"regexp": "^\\[[:-\\s\\d]+\\] waiting for changes\\.\\.\\.$"
32-
}
33-
}
13+
"problemMatcher": "$esbuild-watch",
14+
"isBackground": true
15+
},
16+
{
17+
"label": "build-test-vscode-watch",
18+
"icon": {
19+
"color": "terminal.ansiBlue",
20+
"id": "beaker"
3421
},
22+
"type": "npm",
23+
"script": "build-test-vscode-watch",
24+
"group": "build",
25+
"problemMatcher": "$esbuild-watch",
3526
"isBackground": true
3627
},
3728
{
3829
"label": "test-watch",
3930
"icon": {
40-
"color": "terminal.ansiCyan",
41-
"id": "sync"
31+
"color": "terminal.ansiBlue",
32+
"id": "beaker"
4233
},
4334
"type": "npm",
4435
"script": "test-watch",
4536
"group": "test",
37+
"isBackground": true,
4638
"problemMatcher": {
4739
"owner": "typescript",
4840
"source": "mocha",
4941
"pattern": {
50-
"regexp": "^(.*):(\\d+):(\\d+) - (error|warning) TS(\\d+): (.*)$",
51-
"file": 1,
52-
"line": 2,
53-
"column": 3,
54-
"severity": 4,
55-
"code": 5,
56-
"message": 6
42+
"regexp": "\\w+?(Error): (.+)\\w+?\\((.+)\\)",
43+
"severity": 1,
44+
"message": 2,
45+
"file": 3
5746
},
5847
"severity": "info",
5948
"fileLocation": ["relative", "${workspaceFolder}"],
@@ -64,8 +53,7 @@
6453
"regexp": "^ℹ \\[mocha\\] waiting for changes...$"
6554
}
6655
}
67-
},
68-
"isBackground": true
56+
}
6957
}
7058
]
7159
}

package.json

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,24 @@
8686
],
8787
"main": "./dist/extension.js",
8888
"devDependencies": {
89-
"@rollup/plugin-commonjs": "^25.0.7",
90-
"@rollup/plugin-node-resolve": "^15.2.3",
91-
"@rollup/plugin-swc": "^0.3.0",
92-
"@rollup/plugin-terser": "^0.4.4",
93-
"@swc-node/register": "^1.6.8",
9489
"@types/chai": "^4.3.5",
9590
"@types/debounce-promise": "^3.1.9",
9691
"@types/glob": "^8.1.0",
9792
"@types/json-parse-safe": "^2.0.3",
9893
"@types/mocha": "^10.0.6",
9994
"@types/node": "^20.10.6",
10095
"@types/readline-transform": "^1.0.4",
96+
"@types/vscode": "^1.77.0",
10197
"@typescript-eslint/eslint-plugin": "^6.16.0",
10298
"@typescript-eslint/parser": "^6.16.0",
10399
"@vscode/dts": "^0.4.0",
100+
"@vscode/test-cli": "^0.0.4",
104101
"@vscode/test-electron": "^2.3.8",
105102
"@vscode/vsce": "^2.22.0",
106103
"chai": "^5.0.0",
107104
"debounce-promise": "^3.1.2",
108105
"esbuild": "^0.19.11",
106+
"esbuild-register": "^3.5.0",
109107
"eslint": "^8.56.0",
110108
"eslint-config-prettier": "^9.1.0",
111109
"eslint-config-standard-with-typescript": "^43.0.0",
@@ -116,13 +114,11 @@
116114
"json-parse-safe": "^2.0.0",
117115
"lookpath": "^1.2.2",
118116
"mocha": "^10.2.0",
119-
"mocha-multi-reporters": "^1.5.1",
120117
"path": "^0.12.7",
121118
"pkgroll": "^2.0.1",
122119
"prettier": "^3.1.1",
123120
"prettier-eslint": "^16.2.0",
124121
"readline-transform": "^1.0.0",
125-
"rollup": "^4.9.2",
126122
"sinon": "^17.0.1",
127123
"tslog": "^4.9.2",
128124
"typescript": "^5.3.3",
@@ -145,25 +141,32 @@
145141
}
146142
],
147143
"scripts": {
144+
"esbuild-base": "pnpm esbuild --minify --bundle --platform=node --target=node18.15 --format=cjs --sourcemap --sources-content=false --external:mocha --external:vscode",
148145
"package": "vsce package --no-update-package-json --no-git-tag-version --no-dependencies",
149146
"publish": "pnpm run publishStable --pre-release --no-git-tag-version",
150147
"publishStable": "vsce publish --no-update-package-json --no-dependencies",
151-
"build": "rollup --config",
148+
"build": "pnpm run esbuild-base src/extension.ts --outdir=dist",
152149
"build-watch": "pnpm run build --watch",
150+
"build-test-vscode": "pnpm run esbuild-base src/**/*.vscode.test.ts test/**/*.vscode.test.ts --outdir=dist/test",
151+
"build-test-vscode-watch": "pnpm run build-test-vscode --watch",
152+
"test-mocha": "mocha",
153+
"test-mocha-vscode": "pnpm vscode-test",
154+
"test": "pnpm test-mocha && pnpm test-mocha-vscode",
155+
"test-watch": "pnpm test-mocha --watch",
153156
"lint-eslint": "eslint . --ext .ts",
154157
"lint-prettier": "prettier --check .",
155158
"lint-tsc": "tsc --noemit",
156159
"lint": "pnpm lint-eslint || pnpm lint-prettier || pnpm lint-tsc",
157-
"test-mocha": "mocha",
158-
"test-mocha-vscode": "node -r @swc-node/register test/runTests.ts",
159-
"test": "pnpm test-mocha && pnpm test-mocha-vscode",
160-
"test-watch": "pnpm test-mocha --watch",
161160
"download-api": "vscode-dts main",
162161
"postdownload-api": "vscode-dts main",
163162
"vscode:prepublish": "pnpm run build"
164163
},
165164
"dependencies": {
166-
"@ctiterm/strip-ansi": "^1.0.0",
167-
"@swc/core": "^1.3.102"
165+
"@ctiterm/strip-ansi": "^1.0.0"
166+
},
167+
"pnpm": {
168+
"patchedDependencies": {
169+
"@vscode/test-cli@0.0.4": "patches/@vscode__test-cli@0.0.4.patch"
170+
}
168171
}
169172
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/out/bin.mjs b/out/bin.mjs
2+
index 5282c55bd62d0b77c17f77a173ff848286c0c2f8..857e6d9ca1b6275185c11ab7ebadb1646b5a5afe 100644
3+
--- a/out/bin.mjs
4+
+++ b/out/bin.mjs
5+
@@ -11,6 +11,9 @@ import { dirname, isAbsolute, join, resolve } from 'path';
6+
import supportsColor from 'supports-color';
7+
import { fileURLToPath, pathToFileURL } from 'url';
8+
import yargs from 'yargs';
9+
+import { createRequire } from 'node:module';
10+
+
11+
+const require = createRequire(import.meta.url);
12+
const rulesAndBehavior = 'Mocha: Rules & Behavior';
13+
const reportingAndOutput = 'Mocha: Reporting & Output';
14+
const fileHandling = 'Mocha: File Handling';

0 commit comments

Comments
 (0)