Skip to content

Commit 9838428

Browse files
author
vdemedes
committed
Measure time using Date.now() instead of process.hrtime()
Duration measured in nanoseconds does not give any valuable information to the developer. It makes sense to display time only for long-running tests, above some threshold. Also, process.hrtime() is not available in browsers, so it would need replacement anyway.
1 parent 6abe83a commit 9838428

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
var hrtime = require('pretty-hrtime');
2+
var prettyMs = require('pretty-ms');
33
var chalk = require('chalk');
44
var figures = require('figures');
55
var Squeak = require('squeak');
@@ -24,7 +24,7 @@ function test(err, title, duration) {
2424
return;
2525
}
2626

27-
log.success(title + ' ' + chalk.dim('(' + hrtime(duration) + ')'));
27+
log.success(title + ' ' + chalk.dim('(' + prettyMs(duration) + ')'));
2828
}
2929

3030
function stack(results) {

lib/test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ function Test(title, fn) {
2424

2525
// store the time point
2626
// before test execution
27-
// to pass it to process.hrtime()
28-
// and calculate the total time spent in test
27+
// to calculate the total time spent in test
2928
this._timeStart = 0;
3029
}
3130

@@ -73,7 +72,7 @@ Test.prototype.run = function (cb) {
7372
this.exit();
7473
}
7574

76-
this._timeStart = process.hrtime();
75+
this._timeStart = Date.now();
7776

7877
try {
7978
var ret = this.fn(this);
@@ -107,7 +106,7 @@ Test.prototype.end = function () {
107106

108107
Test.prototype.exit = function () {
109108
// calculate total time spent in test
110-
var duration = process.hrtime(this._timeStart);
109+
var duration = Date.now() - this._timeStart;
111110

112111
if (this.planCount !== null && this.planCount !== this.assertCount) {
113112
this.assertError = new assert.AssertionError({

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"globby": "^2.0.0",
5555
"meow": "^3.3.0",
5656
"plur": "^2.0.0",
57-
"pretty-hrtime": "^1.0.0",
57+
"pretty-ms": "^2.0.0",
5858
"squeak": "^1.2.0",
5959
"update-notifier": "^0.5.0"
6060
},

0 commit comments

Comments
 (0)