Skip to content

Commit

Permalink
chore(testrunner): introduce tests for TestRunner (#4773)
Browse files Browse the repository at this point in the history
This adds some basic tests for the test runner.
  • Loading branch information
aslushnikov committed Jul 30, 2019
1 parent 3bbc45a commit 7406b18
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"funit": "BROWSER=firefox node test/test.js",
"debug-unit": "node --inspect-brk test/test.js",
"test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6-transformer && npm run test-types",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6-transformer && npm run test-types && node utils/testrunner/test/test.js",
"install": "node install.js",
"lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .) && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",
Expand Down
13 changes: 10 additions & 3 deletions utils/testrunner/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UserCallback {
const from = frame.indexOf('(');
frame = frame.substring(from + 1, frame.length - 1);
} else {
frame = frame.substring('at '.length + 1);
frame = frame.substring('at '.length);
}

const match = frame.match(/^(.*):(\d+):(\d+)$/);
Expand Down Expand Up @@ -348,14 +348,21 @@ class TestRunner extends EventEmitter {
async run() {
const runnableTests = this._runnableTests();
this.emit(TestRunner.Events.Started, runnableTests);
const pass = new TestPass(this, this._rootSuite, runnableTests, this._parallel, this._breakOnFailure);
const termination = await pass.run();
this._runningPass = new TestPass(this, this._rootSuite, runnableTests, this._parallel, this._breakOnFailure);
const termination = await this._runningPass.run();
this._runningPass = null;
if (termination)
this.emit(TestRunner.Events.Terminated, termination.message, termination.error);
else
this.emit(TestRunner.Events.Finished);
}

terminate() {
if (!this._runningPass)
return;
this._runningPass._terminate('Terminated with |TestRunner.terminate()| call', null);
}

timeout() {
return this._timeout;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/testrunner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test/test.js"
},
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions utils/testrunner/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {TestRunner, Matchers, Reporter} = require('..');

const testRunner = new TestRunner();
const {expect} = new Matchers();

require('./testrunner.spec.js').addTests({testRunner, expect});

new Reporter(testRunner, {
verbose: process.argv.includes('--verbose'),
summary: true,
projectFolder: require('path').join(__dirname, '..'),
showSlowTests: 0,
});
testRunner.run();

0 comments on commit 7406b18

Please sign in to comment.