mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Make all reporters work
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
--ui tdd
|
||||
--colors
|
||||
--reporter spec
|
||||
--require source-map-support/register
|
||||
--exit
|
||||
./out/test/suite/**/*.test.js
|
||||
@ -2,13 +2,14 @@ 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 vscode from 'vscode';
|
||||
// import * as myExtension from '../extension';
|
||||
|
||||
// Defines a Mocha test suite to group tests of similar kind together
|
||||
suite('Extension Tests', function() {
|
||||
// Defines a Mocha unit test
|
||||
test('Something 1', function() {
|
||||
vscode.window.showInformationMessage('test')
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
|
||||
@ -1,13 +1,38 @@
|
||||
import * as path from 'path';
|
||||
import * as cp from 'child_process';
|
||||
import * as Mocha from 'mocha';
|
||||
|
||||
export function run(testsRoot: string, cb: (error: any) => void): void {
|
||||
const cmd = cp.spawnSync('npx', ['mocha'], { cwd: path.resolve(__dirname, '../../') })
|
||||
export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
|
||||
let mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
reporter: 'nyan'
|
||||
});
|
||||
mocha.useColors(true)
|
||||
|
||||
console.log(cmd.stdout.toString())
|
||||
if (cmd.status !== 0) {
|
||||
cb(new Error('Mocha test failed'))
|
||||
} else {
|
||||
cb(null);
|
||||
const files = [path.resolve(__dirname, '../../out/test/suite/extension.test.js')];
|
||||
|
||||
files.forEach(f => mocha.addFile(f));
|
||||
|
||||
try {
|
||||
let stdOutMessages = '';
|
||||
|
||||
const processStdoutWrite = process.stdout.write;
|
||||
|
||||
process.stdout.write = (message: string | Buffer) => {
|
||||
if (typeof message !== 'string') {
|
||||
message = message.toString();
|
||||
}
|
||||
stdOutMessages += message;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mocha.run(failures => {
|
||||
cb(null, failures);
|
||||
}).on('test end', () => {
|
||||
process.stdout.write = processStdoutWrite;
|
||||
console.log('\n' + stdOutMessages + '\n');
|
||||
})
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user