Skip to content

Commit

Permalink
Make all reporters work
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed May 23, 2019
1 parent 0f70383 commit cb83f39
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
6 changes: 0 additions & 6 deletions helloworld-test-sample/test/mocha.opts

This file was deleted.

3 changes: 2 additions & 1 deletion helloworld-test-sample/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
43 changes: 34 additions & 9 deletions helloworld-test-sample/test/testRunner.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit cb83f39

Please sign in to comment.