Skip to content

Commit

Permalink
Include beforeEach hooks in --slow timings
Browse files Browse the repository at this point in the history
Previously `beforeEach` hook runtimes were excluded from test times. This is
misleading, since `beforeEach` hooks can take a significant amount of time.
It's better to report this accurately, especially since `beforeEach` hook costs
are not amortized over every test (like `before` hooks are).
  • Loading branch information
kevinburke authored and sgilroy committed Feb 27, 2019
1 parent 9e95d36 commit 1cff7c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ Runnable.prototype.globals = function(globals) {
*/
Runnable.prototype.run = function(fn) {
var self = this;
var start = new Date();
var start;
if (typeof self.start === 'number') {
start = self.start;
} else {
start = Date.now();
}
var ctx = this.ctx;
var finished;
var emitted;
Expand Down
2 changes: 2 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ Runner.prototype.parents = function() {
Runner.prototype.runTest = function(fn) {
var self = this;
var test = this.test;
test.start = self.start;

if (!test) {
return;
Expand Down Expand Up @@ -623,6 +624,7 @@ Runner.prototype.runTests = function(suite, fn) {
}

// execute test and hook(s)
self.start = Date.now();
self.emit(constants.EVENT_TEST_BEGIN, (self.test = test));
self.hookDown(HOOK_TYPE_BEFORE_EACH, function(err, errSuite) {
if (test.isPending()) {
Expand Down

0 comments on commit 1cff7c6

Please sign in to comment.