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": {
"url": "https://github.com/klenty/gunner/issues"
},
"browser": {
"perf_utils": "src/util/perf_hooks.js"
},
"homepage": "https://github.com/klenty/gunner#readme",
"dependencies": {
"@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 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 caller = (test, state) => {
@ -8,11 +6,11 @@ const caller = (test, state) => {
let value, error, errored;
try {
perf.start = performance.now();
perf.start = Date.now();
value = test(state);
perf.end = performance.now();
perf.end = Date.now();
} catch (e) {
perf.end = performance.now();
perf.end = Date.now();
errored = true;
error = e;
}
@ -22,13 +20,13 @@ const caller = (test, state) => {
if (promise) {
return value
.then(res => ({
duration: performance.now() - perf.start,
duration: Date.now() - perf.start,
status: 'ok',
resolve: res,
promise: true
}))
.catch(rej => ({
duration: performance.now() - perf.start,
duration: Date.now() - perf.start,
status: 'notOk',
rejection: rej,
promise: true

4
src/lib/testrunner.js

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

2
src/util/perf_hooks.js

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