This commit is contained in:
Pine Wu
2019-05-23 19:27:01 -07:00
parent 7125ef2fcc
commit 0ff4084ab8
6 changed files with 911 additions and 1017 deletions

View File

@ -0,0 +1,25 @@
import * as path from 'path';
import { runTests } from 'vscode-test';
async function go() {
try {
const extensionPath = path.resolve(__dirname, '../../');
const testRunnerPath = path.resolve(__dirname, './suite');
const testWorkspace = path.resolve(__dirname, '../../test/suite/fixture');
await runTests({
// The folder containing the Extension Manifest package.json
extensionPath,
// The path to test runner
testRunnerPath,
// The workspace to open on starting up VS Code
testWorkspace
});
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
go();

View File

@ -0,0 +1,18 @@
import * as assert from 'assert';
import { before } from 'mocha';
// 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', () => {
before(() => {
vscode.window.showInformationMessage('Start all tests.');
});
test('Sample test', () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});

View File

@ -0,0 +1,31 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
});
mocha.useColors(true);
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return cb(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha
.run(failures => {
cb(null, failures);
});
} catch (err) {
cb(err);
}
});
}