Browse Source

[duration] Replace performance with less resolution Date

master
Muthu Kumar 6 years ago
parent
commit
1f5a37c1e2
  1. 3
      package.json
  2. 2
      sample/sample7.test.js
  3. 12
      src/lib/caller.js
  4. 4
      src/lib/testrunner.js
  5. 2
      src/util/perf_hooks.js

3
package.json

@ -23,9 +23,6 @@
"bugs": { "bugs": {
"url": "https://github.com/klenty/gunner/issues" "url": "https://github.com/klenty/gunner/issues"
}, },
"browser": {
"perf_utils": "src/util/perf_hooks.js"
},
"homepage": "https://github.com/klenty/gunner#readme", "homepage": "https://github.com/klenty/gunner#readme",
"dependencies": { "dependencies": {
"@codefeathers/iseq": "^1.2.1", "@codefeathers/iseq": "^1.2.1",

2
sample/sample7.test.js

@ -99,4 +99,4 @@ gunner.test('(should fail) should not resolve to 5', () =>
const trace = process.argv.slice(2).indexOf('--trace') !== -1; const trace = process.argv.slice(2).indexOf('--trace') !== -1;
const reporter = process.argv.slice(2).indexOf('--log') !== -1; const reporter = process.argv.slice(2).indexOf('--log') !== -1;
gunner.run({ trace, reporter }); gunner.run({ trace, reporter }).then(console.log);

12
src/lib/caller.js

@ -1,5 +1,3 @@
const { performance } = require('perf_hooks');
const { isPromise } = require('../util'); const { isPromise } = require('../util');
const caller = (test, state) => { const caller = (test, state) => {
@ -8,11 +6,11 @@ const caller = (test, state) => {
let value, error, errored; let value, error, errored;
try { try {
perf.start = performance.now(); perf.start = Date.now();
value = test(state); value = test(state);
perf.end = performance.now(); perf.end = Date.now();
} catch (e) { } catch (e) {
perf.end = performance.now(); perf.end = Date.now();
errored = true; errored = true;
error = e; error = e;
} }
@ -22,13 +20,13 @@ const caller = (test, state) => {
if (promise) { if (promise) {
return value return value
.then(res => ({ .then(res => ({
duration: performance.now() - perf.start, duration: Date.now() - perf.start,
status: 'ok', status: 'ok',
resolve: res, resolve: res,
promise: true promise: true
})) }))
.catch(rej => ({ .catch(rej => ({
duration: performance.now() - perf.start, duration: Date.now() - perf.start,
status: 'notOk', status: 'notOk',
rejection: rej, rejection: rej,
promise: true promise: true

4
src/lib/testrunner.js

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

2
src/util/perf_hooks.js

@ -1,2 +0,0 @@
/* global performance */
module.exports = { performance };
Loading…
Cancel
Save