Skip to content

Commit

Permalink
Added basic testing stuff
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 16, 2024
1 parent f4a0c3b commit c1db5d4
Show file tree
Hide file tree
Showing 15 changed files with 1,410 additions and 53 deletions.
12 changes: 12 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: ['out/test/**/*.test.mts'],
version: 'insiders',
workspaceFolder: './testWorkspace',
mocha: {
ui: 'tdd',
timeout: 60000,
},
skipExtensionDependencies: false
});
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index.mjs"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
"${workspaceFolder}/dist/test/**/*.mjs"
],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "watch-test"
}
]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
"kind": "build",
"isDefault": true
}
},
{
"label": "watch-test",
"type": "npm",
"script": "watch-test",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build",
"isDefault": false
}
}
]
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@
"compile-uninstaller": "rollup -c uninstall.rollup.config.mjs --environment BUILD:production",
"compile": "rollup -c",
"watch": "rollup -cw",
"watch-test": "tsc -w --outDir ./out -p ./tsconfig.json -m es2022",
"package": "rimraf dist && node scripts/build.mjs && yarn run compile-uninstaller",
"lint": "eslint src",
"test": "yarn run lint"
"test": "yarn run lint && vscode-test"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
Expand All @@ -278,14 +279,20 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/adm-zip": "^0.5.5",
"@types/glob": "^8.1.0",
"@types/ini": "^4.1.1",
"@types/mocha": "^10.0.8",
"@types/node": "18.17.x",
"@types/uuid": "^10.0.0",
"@types/vscode": "^1.87.0",
"@types/which": "^3.0.4",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"glob": "^11.0.0",
"globals": "^15.9.0",
"mocha": "^10.7.3",
"rollup": "^4.21.0",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
commonjs(),
typescript({
tsconfig: 'tsconfig.json',
exclude: ['src/test/**/*.mts']
}),
],
};
31 changes: 17 additions & 14 deletions src/commands/uninstallPicoSDK.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Command } from "./command.mjs";
import { CommandWithArgs } from "./command.mjs";
import Logger from "../logger.mjs";
import { window } from "vscode";
import { rimraf } from "rimraf";
import { join } from "path";
import { homedir } from "os";
import { unknownErrorToString } from "../utils/errorHelper.mjs";

export default class UninstallPicoSDKCommand extends Command {
export default class UninstallPicoSDKCommand extends CommandWithArgs {
private _logger: Logger = new Logger("UninstallPicoSDKCommand");

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

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

const response = await window.showWarningMessage(
"Uninstalling Pico SDK - Are you sure you want to continue?",
{
modal: true,
detail:
"This will delete the Pico SDK and all its automatically installed " +
"dependencies from the system. This action cannot be undone.",
},
"Yes",
"No"
);
const response = force
? "Yes"
: await window.showWarningMessage(
"Uninstalling Pico SDK - Are you sure you want to continue?",
{
modal: true,
detail:
"This will delete the Pico SDK and all its automatically " +
"installed dependencies from the system. " +
"This action cannot be undone.",
},
"Yes",
"No"
);

if (response === "Yes") {
// uninstall the Pico SDK and all its automatically installed dependencies
Expand Down
27 changes: 27 additions & 0 deletions src/test/runTest.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { resolve } from "path";

import { runTests } from "@vscode/test-electron";

async function main(): Promise<void> {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = resolve(__dirname, "../../");

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = resolve(__dirname, "./suite/index");

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error("Failed to run tests:", err);
process.exit(1);
}
}

main()
.then(() => console.log("Test run finished"))
.catch(err => {
console.error("Test run failed:", err);
});
Loading

0 comments on commit c1db5d4

Please sign in to comment.