Skip to content

Commit

Permalink
Fixed test suites and reporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Sep 1, 2019
1 parent 2187604 commit 1e0ed4e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"_dist_ethers": "rollup -c && rollup -c --configMinify && rollup -c --configModule && rollup -c --configModule --configMinify",
"_dist_tests": "rollup -c --configTest && rollup -c --configTest --configMinify && rollup -c --configTest --configModule && rollup -c --configTest --configModule --configMinify",
"_test_prepare": "npm run _dist_prepare && npm run _dist_tests",
"_test_node": "cd packages/tests && mocha --no-colors --reporter ./tests/reporter ./tests/test-*.js",
"_test_node": "cd packages/tests && mocha --no-colors --reporter ./lib/reporter ./lib/test-*.js",
"test_node": "npm run _test_prepare && npm run _test_node",
"_dist_old": "npm run clean && npm run bootstrap && npm run build && lerna run dist",
"old-test": "npm run _dist_old && npm run test-check",
Expand All @@ -21,6 +21,7 @@
"old-test-aion-node": "cd packages/aion-tests && mocha --no-colors --reporter ../tests/tests/reporter ./tests/test-*.js",
"update-versions": "npm run _dist_prepare && node ./admin/cmds/update-versions",
"publish-all": "node ./admin/cmds/publish",
"lock-versions": "node ./admin/cmds/lock-versions",
"build-docs": "flatworm docs.wrm docs"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/tests/lib/reporter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Runner {
on(event: string, callback: (...args: Array<any>) => void): Runner;
}
declare function Reporter(runner: Runner): void;
export = Reporter;
111 changes: 111 additions & 0 deletions packages/tests/lib/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';
function getTime() {
return (new Date()).getTime();
}
function trunc(value) {
if (value >= 0) {
return Math.floor(value);
}
return Math.ceil(value);
}
function getDelta(t0) {
var ds = trunc((getTime() - t0) / 1000);
var minutes = trunc(ds / 60);
var seconds = String(trunc(ds) % 60);
while (seconds.length < 2) {
seconds = '0' + seconds;
}
return '(' + minutes + ':' + seconds + ')';
}
function Reporter(runner) {
var suites = [];
var lastOutput = getTime();
function getIndent() {
var result = '';
for (var i = 0; i < suites.length; i++) {
result += ' ';
}
return result;
}
function log(message) {
if (!message) {
message = '';
}
var indent = getIndent();
console.log(indent + message);
lastOutput = getTime();
}
runner.on('suite', function (suite) {
if (!suite.title) {
log('Testing: Found ' + suite.suites.length + ' test suites');
}
else {
var filename = (suite.file || '').split('/').pop();
if (filename) {
filename = ' (' + filename + ')';
}
log('Test Suite: ' + suite.title + filename);
}
suites.push(suite);
suite._t0 = getTime();
suite._countFail = 0;
suite._countPass = 0;
suite._countTotal = 0;
});
runner.on('suite end', function () {
var suite = suites.pop();
var failure = '';
if (suite._countTotal > suite._countPass) {
failure = ' (' + (suite._countTotal - suite._countPass) + ' failed)';
}
log(' Total Tests: ' + suite._countPass + '/' + suite._countTotal + ' passed ' + getDelta(suite._t0) + failure);
log();
if (suites.length > 0) {
var currentSuite = suites[suites.length - 1];
currentSuite._countFail += suite._countFail;
currentSuite._countPass += suite._countPass;
currentSuite._countTotal += suite._countTotal;
}
});
runner.on('test', function (test) {
var currentSuite = suites[suites.length - 1];
if (((getTime() - lastOutput) / 1000) > 60) {
log('[ Still running suite - test #' + currentSuite._countTotal + ' ]');
lastOutput = getTime();
}
currentSuite._countTotal++;
});
runner.on('fail', function (test, error) {
var currentSuite = suites[suites.length - 1];
currentSuite._countFail++;
var countFail = currentSuite._countFail;
if (countFail > 100) {
if (countFail === 101) {
log('[ Over 100 errors; skipping remaining suite output ]');
}
return;
}
if (countFail > 25) {
log('Failure: ' + test.title + ' (too many errors; skipping dump)');
return;
}
log('Failure: ' + test.title);
error.toString().split('\n').forEach(function (line) {
log(' ' + line);
});
Object.keys(error).forEach(function (key) {
log(' ' + key + ': ' + error[key]);
});
if (error.stack) {
log("Stack Trace:");
error.stack.split('\n').forEach(function (line) {
log(' ' + line);
});
}
});
runner.on('pass', function (test) {
var currentSuite = suites[suites.length - 1];
currentSuite._countPass++;
});
}
module.exports = Reporter;
4 changes: 1 addition & 3 deletions packages/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
"./thirdparty.d.ts",
"./src.ts/*"
],
"exclude": [
"./src.ts/reporter.ts"
]
"exclude": [ ]
}

0 comments on commit 1e0ed4e

Please sign in to comment.