Added empty test suite

This commit is contained in:
Dag 2023-01-19 23:43:26 +01:00
parent 35da45bc3c
commit b4f7e6c830
6 changed files with 104 additions and 7 deletions

21
.eslintrc.json Normal file
View File

@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

4
package-lock.json generated
View File

@ -13,8 +13,8 @@
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/node": "16.x", "@types/node": "16.x",
"@types/vscode": "^1.74.0", "@types/vscode": "^1.74.0",
"@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.45.0", "@typescript-eslint/parser": "^5.48.2",
"@vscode/test-electron": "^2.2.0", "@vscode/test-electron": "^2.2.0",
"eslint": "^8.28.0", "eslint": "^8.28.0",
"glob": "^8.0.3", "glob": "^8.0.3",

View File

@ -53,17 +53,17 @@
"test": "node ./out/test/runTest.js" "test": "node ./out/test/runTest.js"
}, },
"devDependencies": { "devDependencies": {
"@types/vscode": "^1.74.0",
"@types/glob": "^8.0.0", "@types/glob": "^8.0.0",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/node": "16.x", "@types/node": "16.x",
"@typescript-eslint/eslint-plugin": "^5.45.0", "@types/vscode": "^1.74.0",
"@typescript-eslint/parser": "^5.45.0", "@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"@vscode/test-electron": "^2.2.0",
"eslint": "^8.28.0", "eslint": "^8.28.0",
"glob": "^8.0.3", "glob": "^8.0.3",
"mocha": "^10.1.0", "mocha": "^10.1.0",
"typescript": "^4.9.3", "typescript": "^4.9.3"
"@vscode/test-electron": "^2.2.0"
}, },
"bugs": { "bugs": {
"url": "https://github.com/svaberg/SWMF-grammar/issues" "url": "https://github.com/svaberg/SWMF-grammar/issues"

23
src/test/runTest.ts Normal file
View File

@ -0,0 +1,23 @@
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.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');
process.exit(1);
}
}
main();

View File

@ -0,0 +1,15 @@
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});

38
src/test/suite/index.ts Normal file
View File

@ -0,0 +1,38 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
export function run(): Promise<void> {
// Create the mocha test
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);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}