Browse Source

[test-recorder] Fixes to getting correct time

master
Muthu Kumar 6 years ago
parent
commit
b5ab09095d
  1. 10
      src/lib/caller.js
  2. 4
      src/lib/testrunner.js
  3. 4
      src/runner/index.js
  4. 7
      src/util/nodeutils.js

10
src/lib/caller.js

@ -6,11 +6,11 @@ const caller = (test, state) => {
let value, error, errored; let value, error, errored;
try { try {
perf.start = Date.now(); perf.start = new Date();
value = test(state); value = test(state);
perf.end = Date.now(); perf.end = new Date();
} catch (e) { } catch (e) {
perf.end = Date.now(); perf.end = new Date();
errored = true; errored = true;
error = e; error = e;
} }
@ -20,13 +20,13 @@ const caller = (test, state) => {
if (promise) { if (promise) {
return value return value
.then(res => ({ .then(res => ({
duration: Date.now() - perf.start, duration: new Date() - perf.start,
status: 'ok', status: 'ok',
resolve: res, resolve: res,
promise: true promise: true
})) }))
.catch(rej => ({ .catch(rej => ({
duration: Date.now() - perf.start, duration: new Date() - perf.start,
status: 'notOk', status: 'notOk',
rejection: rej, rejection: rej,
promise: true promise: true

4
src/lib/testrunner.js

@ -122,14 +122,14 @@ const reduceQueue =
*/ */
const testrunner = (instance) => { const testrunner = (instance) => {
const perf = { start: Date.now() }; const perf = { start: new Date() };
return Promise.object(pipe( return Promise.object(pipe(
buildTestQueue, buildTestQueue,
reduceQueue, reduceQueue,
pick('results'), pick('results'),
)(instance)).then(results => { )(instance)).then(results => {
perf.end = Date.now(); perf.end = new Date();
results.end = perf.end.toUTCString(); results.end = perf.end.toUTCString();
results.start = perf.start.toUTCString(); results.start = perf.start.toUTCString();
results.duration = perf.end - perf.start; results.duration = perf.end - perf.start;

4
src/runner/index.js

@ -26,7 +26,7 @@ const runner = instances => (options = {}) => {
if (RunInstances.length !== instances.length) if (RunInstances.length !== instances.length)
throw new Error (`Not all instances were of type ${type}`); throw new Error (`Not all instances were of type ${type}`);
const perf = { start: Date.now() }; const perf = { start: new Date() };
return Promise.all(RunInstances.map(instance => { return Promise.all(RunInstances.map(instance => {
return ( return (
@ -35,7 +35,7 @@ const runner = instances => (options = {}) => {
); );
})) }))
.then(results => { .then(results => {
perf.end = Date.now(); perf.end = new Date();
results.start = perf.start.toUTCString(); results.start = perf.start.toUTCString();
results.end = perf.end.toUTCString(); results.end = perf.end.toUTCString();
results.duration = perf.end - perf.start; results.duration = perf.end - perf.start;

7
src/util/nodeutils.js

@ -2,6 +2,13 @@ module.exports = {
clear: () => { clear: () => {
if (typeof global === 'undefined'
|| typeof global.process === 'undefined'
|| typeof global.process.stdout === 'undefined'
) return;
const process = global.process;
// clear screen // clear screen
process.stdout.write('\u001b[2J'); process.stdout.write('\u001b[2J');
// set cursor position to top // set cursor position to top

Loading…
Cancel
Save