Make all reporters work

This commit is contained in:
Pine Wu
2019-05-22 18:57:41 -07:00
parent 0f703833f7
commit cb83f3909e
3 changed files with 36 additions and 16 deletions

View File

@ -1,6 +0,0 @@
--ui tdd
--colors
--reporter spec
--require source-map-support/register
--exit
./out/test/suite/**/*.test.js

View File

@ -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));
});

View File

@ -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);
}
}
}