diff --git a/helloworld-test-sample/test/mocha.opts b/helloworld-test-sample/test/mocha.opts deleted file mode 100644 index 01d17f94..00000000 --- a/helloworld-test-sample/test/mocha.opts +++ /dev/null @@ -1,6 +0,0 @@ ---ui tdd ---colors ---reporter spec ---require source-map-support/register ---exit -./out/test/suite/**/*.test.js \ No newline at end of file diff --git a/helloworld-test-sample/test/suite/extension.test.ts b/helloworld-test-sample/test/suite/extension.test.ts index 9e22d472..2b1ad1ee 100644 --- a/helloworld-test-sample/test/suite/extension.test.ts +++ b/helloworld-test-sample/test/suite/extension.test.ts @@ -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)); }); diff --git a/helloworld-test-sample/test/testRunner.ts b/helloworld-test-sample/test/testRunner.ts index 6c38c885..af62551b 100644 --- a/helloworld-test-sample/test/testRunner.ts +++ b/helloworld-test-sample/test/testRunner.ts @@ -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); } -} \ No newline at end of file +}