mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Update
This commit is contained in:
25
helloworld-test-sample/src/test/runTest.ts
Normal file
25
helloworld-test-sample/src/test/runTest.ts
Normal 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();
|
||||
18
helloworld-test-sample/src/test/suite/extension.test.ts
Normal file
18
helloworld-test-sample/src/test/suite/extension.test.ts
Normal 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));
|
||||
});
|
||||
});
|
||||
31
helloworld-test-sample/src/test/suite/index.ts
Normal file
31
helloworld-test-sample/src/test/suite/index.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user