From 657a0394f56b51a13c691477c2b0dcf74678fd7c Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 4 May 2020 22:47:06 -0400 Subject: [PATCH] Safer test suite reporter timer. --- packages/tests/src.ts/reporter.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/tests/src.ts/reporter.ts b/packages/tests/src.ts/reporter.ts index 4c35ba200d..32b98d0812 100644 --- a/packages/tests/src.ts/reporter.ts +++ b/packages/tests/src.ts/reporter.ts @@ -37,7 +37,16 @@ interface Runner { export function Reporter(runner: Runner) { let suites: Array = []; + // 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 = ''; @@ -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];