Skip to content

Commit

Permalink
add npm packages and config
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolirob committed Mar 8, 2023
1 parent d8576f1 commit 98ff5d8
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
"--extensionTestsPath=${workspaceFolder}/out/test/e2e/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "npm: watch"
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"package": "vsce package",
"test": "npm run compile && node ./node_modules/vscode/bin/test",
"test": "node ./out/test/runTest.ts",
"lint": "eslint -c .eslintrc.json --ext .ts ./src"
},
"engines": {
Expand All @@ -51,6 +51,7 @@
"spark-md5": "^3.0.2"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "^18.14.0",
"@types/semver": "^7.3.13",
Expand All @@ -59,7 +60,10 @@
"@types/vscode": "^1.75.1",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@vscode/test-electron": "^2.3.0",
"eslint": "^8.34.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"prettier": "^2.8.4",
"typescript": "^4.9.5"
},
Expand Down
31 changes: 31 additions & 0 deletions src/test/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as path from "path";
import * as Mocha from "mocha";
import * as glob from "glob";

export function run(): Promise<void> {
const mocha = new Mocha({ ui: "tdd", color: true });
const testsRoot = path.resolve(__dirname, "..");

return new Promise((c, e) => {
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}

files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));

try {
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
11 changes: 11 additions & 0 deletions src/test/e2e/slither-vscode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as assert from "assert";

import * as vscode from "vscode";

suite("Slither-VSCode Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test("example test", () => {
assert(true, "Somehow this failed");
});
});
20 changes: 20 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as path from "path";

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

async function main() {
try {
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../");

// Passed to `--extensionTestsPath`
const extensionTestsPath = path.resolve(__dirname, "./e2e/index");

await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error("Failed to run tests", err);
process.exit(1);
}
}

main();
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"module": "commonjs",
"target": "ES2020",
"outDir": "out",
"lib": ["es6"],
"lib": ["ES2020"],
"sourceMap": true,
"rootDir": "src",
/* Strict Type-Checking Option */
Expand Down

0 comments on commit 98ff5d8

Please sign in to comment.