Skip to content

Commit 5a9e122

Browse files
committed
✨ feat: add testing setup
1 parent 8196dd0 commit 5a9e122

File tree

5 files changed

+377
-32
lines changed

5 files changed

+377
-32
lines changed

.vscode-test.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { defineConfig } from '@vscode/test-cli';
22

33
export default defineConfig({
4-
files: 'out/test/**/*.test.js',
4+
files: 'dist/test/**/*.test.js',
5+
workspaceFolder: '.',
6+
mocha: {
7+
ui: 'tdd',
8+
timeout: 20000
9+
}
510
});

esbuild.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ const esbuildProblemMatcherPlugin = {
2424
};
2525

2626
async function main() {
27-
const ctx = await esbuild.context({
28-
entryPoints: [
29-
'src/extension.ts'
30-
],
27+
// Build extension
28+
const extensionCtx = await esbuild.context({
29+
entryPoints: ['src/extension.ts'],
3130
bundle: true,
3231
format: 'cjs',
3332
minify: production,
@@ -37,16 +36,33 @@ async function main() {
3736
outfile: 'dist/extension.js',
3837
external: ['vscode'],
3938
logLevel: 'silent',
40-
plugins: [
41-
/* add to the end of plugins array */
42-
esbuildProblemMatcherPlugin,
43-
],
39+
plugins: [esbuildProblemMatcherPlugin],
40+
});
41+
42+
// Build tests
43+
const testCtx = await esbuild.context({
44+
entryPoints: ['src/test/extension.test.ts'],
45+
bundle: true,
46+
format: 'cjs',
47+
minify: false,
48+
sourcemap: true,
49+
sourcesContent: false,
50+
platform: 'node',
51+
outdir: 'dist/test',
52+
external: ['vscode', 'mocha'],
53+
logLevel: 'silent',
54+
plugins: [esbuildProblemMatcherPlugin],
4455
});
4556
if (watch) {
46-
await ctx.watch();
57+
await Promise.all([
58+
extensionCtx.watch(),
59+
testCtx.watch()
60+
]);
4761
} else {
48-
await ctx.rebuild();
49-
await ctx.dispose();
62+
await extensionCtx.rebuild();
63+
await testCtx.rebuild();
64+
await extensionCtx.dispose();
65+
await testCtx.dispose();
5066
}
5167
}
5268

package-lock.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
},
3434
"ddev-phpmd.validateOn": {
3535
"type": "string",
36-
"enum": ["save", "type"],
36+
"enum": [
37+
"save",
38+
"type"
39+
],
3740
"default": "save",
3841
"description": "Run validation when you save the file or when you type"
3942
},
@@ -42,12 +45,23 @@
4245
"items": {
4346
"type": "string"
4447
},
45-
"default": ["cleancode", "codesize", "controversial", "design", "naming", "unusedcode"],
48+
"default": [
49+
"cleancode",
50+
"codesize",
51+
"controversial",
52+
"design",
53+
"naming",
54+
"unusedcode"
55+
],
4656
"description": "PHPMD rulesets to use"
4757
},
4858
"ddev-phpmd.minSeverity": {
4959
"type": "string",
50-
"enum": ["error", "warning", "info"],
60+
"enum": [
61+
"error",
62+
"warning",
63+
"info"
64+
],
5165
"default": "warning",
5266
"description": "Minimum severity level for reported issues"
5367
},
@@ -72,24 +86,26 @@
7286
"watch:esbuild": "node esbuild.js --watch",
7387
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
7488
"package": "npm run check-types && npm run lint && node esbuild.js --production",
75-
"compile-tests": "tsc -p . --outDir out",
76-
"watch-tests": "tsc -p . -w --outDir out",
77-
"pretest": "npm run compile-tests && npm run compile && npm run lint",
89+
"compile-tests": "node esbuild.js",
90+
"watch-tests": "node esbuild.js --watch",
91+
"pretest": "npm run compile-tests && npm run lint",
7892
"check-types": "tsc --noEmit",
7993
"lint": "eslint src",
8094
"test": "vscode-test"
8195
},
8296
"devDependencies": {
83-
"@types/vscode": "^1.100.0",
8497
"@types/mocha": "^10.0.10",
8598
"@types/node": "20.x",
99+
"@types/sinon": "^17.0.4",
100+
"@types/vscode": "^1.100.0",
86101
"@typescript-eslint/eslint-plugin": "^8.31.1",
87102
"@typescript-eslint/parser": "^8.31.1",
88-
"eslint": "^9.25.1",
103+
"@vscode/test-cli": "^0.0.10",
104+
"@vscode/test-electron": "^2.5.2",
89105
"esbuild": "^0.25.3",
106+
"eslint": "^9.25.1",
90107
"npm-run-all": "^4.1.5",
91-
"typescript": "^5.8.3",
92-
"@vscode/test-cli": "^0.0.10",
93-
"@vscode/test-electron": "^2.5.2"
108+
"sinon": "^20.0.0",
109+
"typescript": "^5.8.3"
94110
}
95111
}

0 commit comments

Comments
 (0)