Skip to content

Commit

Permalink
Safer test suite reporter timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 5, 2020
1 parent ab7c781 commit 657a039
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/tests/src.ts/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ interface Runner {
export function Reporter(runner: Runner) {
let suites: Array<Suite> = [];

// Force Output; Keeps the console output alive with periodic updates
let lastOutput = getTime();
function forceOutput() {
if (((getTime() - lastOutput) / 1000) > MAX_DELAY) {
const currentSuite = suites[suites.length - 1];
log(`[ Still running suite - test # ${ (currentSuite ? currentSuite._countTotal: "0") } ]`);
}
}
const timer = setInterval(forceOutput, 1000);


function getIndent(): string {
let result = '';
Expand Down Expand Up @@ -70,28 +79,21 @@ export function Reporter(runner: Runner) {
let suite = suites.pop();
let failure = '';
if (suite._countTotal > suite._countPass) {
failure = ' (' + (suite._countTotal - suite._countPass) + ' failed)';
failure = ' (' + (suite._countTotal - suite._countPass) + ' failed) *****';
}
log(' Total Tests: ' + suite._countPass + '/' + suite._countTotal + ' passed ' + getDelta(suite._t0) + failure);
log();

if (suites.length > 0) {
let currentSuite = suites[suites.length - 1];
currentSuite._countFail += suite._countFail;
currentSuite._countPass += suite._countPass;
currentSuite._countTotal += suite._countTotal;
} else {
clearTimeout(timer);
}
});

function forceOutput() {
if (((getTime() - lastOutput) / 1000) > MAX_DELAY) {
const currentSuite = suites[suites.length - 1];
log(`[ Still running suite - test # ${ (currentSuite ? currentSuite._countTotal: "0") } ]`);
}
}

const timer = setInterval(forceOutput, 1000);
if (timer.unref) { timer.unref(); }

runner.on('test', function(test) {
forceOutput();
const currentSuite = suites[suites.length - 1];
Expand Down

0 comments on commit 657a039

Please sign in to comment.