Skip to content

Commit

Permalink
update all extensions to use the same new test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Rogers committed Jun 25, 2021
1 parent c9f0739 commit cc8a083
Show file tree
Hide file tree
Showing 15 changed files with 2,160 additions and 96 deletions.
7 changes: 4 additions & 3 deletions vscode-langserver-shacl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "yarn run compile && sh ./scripts/e2e-tests.sh"
"test": "yarn run compile && node ./out/test/runTest.js"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^2.2.42",
"@types/node": "^8.10.25",
"chai": "^4.2.0",
"mocha": "^9.0.1",
"tslint": "^5.8.0",
"typescript": "^4.3.2",
"vscode": "^1.1.37"
"vscode": "^1.1.37",
"vscode-test": "^1.5.2"
},
"dependencies": {
"shacl-language-server": "^1.5.0",
Expand Down
7 changes: 0 additions & 7 deletions vscode-langserver-shacl/scripts/e2e-tests.sh

This file was deleted.

44 changes: 24 additions & 20 deletions vscode-langserver-shacl/src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
// host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.
import * as path from "path";
import * as Mocha from "mocha";

import * as testRunner from "vscode/lib/testrunner";
export function run(): Promise<void> {
const mocha = new Mocha({
// @ts-ignore: Mocha types are missing `color`
color: true,
ui: "bdd",
timeout: 5000,
});

// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: "bdd",
useColors: true, // colored output from test results
timeout: 10000 // allow VSCode and server time to start
});
return new Promise((c, e) => {
mocha.addFile(path.resolve(__dirname, "extension.test.js"));

module.exports = testRunner;
try {
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
}
36 changes: 36 additions & 0 deletions vscode-langserver-shacl/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as cp from "child_process";
import * as path from "path";
import {
downloadAndUnzipVSCode,
runTests,
resolveCliPathFromVSCodeExecutablePath,
} from "vscode-test";

async function main() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
const extensionTestsPath = path.resolve(__dirname, "./index");
const vscodeExecutablePath = await downloadAndUnzipVSCode();
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(cliPath, ["--disable-gpu", "--disable-extensions"], {
encoding: "utf-8",
stdio: "inherit",
});

// Run the extension test
await runTests({
// Use the specified `code` executable
vscodeExecutablePath,
// @ts-ignore: vscode-test types aren't right
extensionDevelopmentPath,
extensionTestsPath,
});
} catch (err) {
console.error("Failed to run tests");
process.exit(1);
}
}

main();
Loading

0 comments on commit cc8a083

Please sign in to comment.