Skip to content

Commit c1db5d4

Browse files
committed
Added basic testing stuff
Signed-off-by: paulober <[email protected]>
1 parent f4a0c3b commit c1db5d4

File tree

15 files changed

+1410
-53
lines changed

15 files changed

+1410
-53
lines changed

.vscode-test.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
3+
export default defineConfig({
4+
files: ['out/test/**/*.test.mts'],
5+
version: 'insiders',
6+
workspaceFolder: './testWorkspace',
7+
mocha: {
8+
ui: 'tdd',
9+
timeout: 60000,
10+
},
11+
skipExtensionDependencies: false
12+
});

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"request": "launch",
2424
"args": [
2525
"--extensionDevelopmentPath=${workspaceFolder}",
26-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
26+
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index.mjs"
2727
],
2828
"outFiles": [
29-
"${workspaceFolder}/out/test/**/*.js"
29+
"${workspaceFolder}/dist/test/**/*.mjs"
3030
],
31-
"preLaunchTask": "${defaultBuildTask}"
31+
"preLaunchTask": "watch-test"
3232
}
3333
]
3434
}

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
"kind": "build",
1717
"isDefault": true
1818
}
19+
},
20+
{
21+
"label": "watch-test",
22+
"type": "npm",
23+
"script": "watch-test",
24+
"problemMatcher": "$tsc-watch",
25+
"isBackground": true,
26+
"presentation": {
27+
"reveal": "never",
28+
"group": "watchers"
29+
},
30+
"group": {
31+
"kind": "build",
32+
"isDefault": false
33+
}
1934
}
2035
]
2136
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@
267267
"compile-uninstaller": "rollup -c uninstall.rollup.config.mjs --environment BUILD:production",
268268
"compile": "rollup -c",
269269
"watch": "rollup -cw",
270+
"watch-test": "tsc -w --outDir ./out -p ./tsconfig.json -m es2022",
270271
"package": "rimraf dist && node scripts/build.mjs && yarn run compile-uninstaller",
271272
"lint": "eslint src",
272-
"test": "yarn run lint"
273+
"test": "yarn run lint && vscode-test"
273274
},
274275
"devDependencies": {
275276
"@eslint/js": "^9.9.0",
@@ -278,14 +279,20 @@
278279
"@rollup/plugin-terser": "^0.4.4",
279280
"@rollup/plugin-typescript": "^11.1.6",
280281
"@types/adm-zip": "^0.5.5",
282+
"@types/glob": "^8.1.0",
281283
"@types/ini": "^4.1.1",
284+
"@types/mocha": "^10.0.8",
282285
"@types/node": "18.17.x",
283286
"@types/uuid": "^10.0.0",
284287
"@types/vscode": "^1.87.0",
285288
"@types/which": "^3.0.4",
289+
"@vscode/test-cli": "^0.0.10",
290+
"@vscode/test-electron": "^2.4.1",
286291
"eslint": "^9.9.0",
287292
"eslint-config-prettier": "^9.1.0",
293+
"glob": "^11.0.0",
288294
"globals": "^15.9.0",
295+
"mocha": "^10.7.3",
289296
"rollup": "^4.21.0",
290297
"tslib": "^2.6.3",
291298
"typescript": "^5.5.4",

rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default {
2424
commonjs(),
2525
typescript({
2626
tsconfig: 'tsconfig.json',
27+
exclude: ['src/test/**/*.mts']
2728
}),
2829
],
2930
};

src/commands/uninstallPicoSDK.mts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Command } from "./command.mjs";
1+
import { CommandWithArgs } from "./command.mjs";
22
import Logger from "../logger.mjs";
33
import { window } from "vscode";
44
import { rimraf } from "rimraf";
55
import { join } from "path";
66
import { homedir } from "os";
77
import { unknownErrorToString } from "../utils/errorHelper.mjs";
88

9-
export default class UninstallPicoSDKCommand extends Command {
9+
export default class UninstallPicoSDKCommand extends CommandWithArgs {
1010
private _logger: Logger = new Logger("UninstallPicoSDKCommand");
1111

1212
public static readonly id = "uninstallPicoSDK";
@@ -15,22 +15,25 @@ export default class UninstallPicoSDKCommand extends Command {
1515
super(UninstallPicoSDKCommand.id);
1616
}
1717

18-
async execute(): Promise<void> {
18+
async execute(force = false): Promise<void> {
1919
// show modal warning that this will delete the Pico SDK and
2020
// all its automatically installed dependencies from the system
2121
// and ask for confirmation
2222

23-
const response = await window.showWarningMessage(
24-
"Uninstalling Pico SDK - Are you sure you want to continue?",
25-
{
26-
modal: true,
27-
detail:
28-
"This will delete the Pico SDK and all its automatically installed " +
29-
"dependencies from the system. This action cannot be undone.",
30-
},
31-
"Yes",
32-
"No"
33-
);
23+
const response = force
24+
? "Yes"
25+
: await window.showWarningMessage(
26+
"Uninstalling Pico SDK - Are you sure you want to continue?",
27+
{
28+
modal: true,
29+
detail:
30+
"This will delete the Pico SDK and all its automatically " +
31+
"installed dependencies from the system. " +
32+
"This action cannot be undone.",
33+
},
34+
"Yes",
35+
"No"
36+
);
3437

3538
if (response === "Yes") {
3639
// uninstall the Pico SDK and all its automatically installed dependencies

src/test/runTest.mts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { resolve } from "path";
2+
3+
import { runTests } from "@vscode/test-electron";
4+
5+
async function main(): Promise<void> {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath = resolve(__dirname, "../../");
10+
11+
// The path to the extension test script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = resolve(__dirname, "./suite/index");
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error("Failed to run tests:", err);
19+
process.exit(1);
20+
}
21+
}
22+
23+
main()
24+
.then(() => console.log("Test run finished"))
25+
.catch(err => {
26+
console.error("Test run failed:", err);
27+
});

0 commit comments

Comments
 (0)