-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testsuite time should include setup and teardown #115
Testsuite time should include setup and teardown #115
Conversation
@@ -9,6 +9,10 @@ var mkdirp = require('mkdirp'); | |||
var md5 = require('md5'); | |||
var stripAnsi = require('strip-ansi'); | |||
|
|||
// Save timer references so that times are correct even if Date is stubbed. | |||
// See https://github.com/mochajs/mocha/issues/237 | |||
var Date = global.Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that mocha uses this in its own reporters, so figured we should do it too.
@@ -258,7 +273,7 @@ MochaJUnitReporter.prototype.getTestsuiteData = function(suite) { | |||
|
|||
var _attr = { | |||
name: this._generateSuiteTitle(suite), | |||
timestamp: new Date().toISOString().slice(0,-5), | |||
timestamp: this._Date.now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of ugly but we need to keep the raw start timestamp and not round it until later. Since we only pass around the XML object, I have to stick it on timestamp
. Later on, we convert this into a string.
A larger refactoring would pass around domain objects and only structure them as XML in getXml
, but that's a larger change.
@@ -202,6 +206,7 @@ function MochaJUnitReporter(runner, options) { | |||
this._runner = runner; | |||
this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle; | |||
this._antId = 0; | |||
this._Date = (options || {}).Date || Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests can mock Date
to simulate time elapsing.
13bd5dc
to
f49aff2
Compare
The `time` attribute on `testsuite` should equal the amount of time between the runner issuing the `suite` and `end suite` events. It was previously calculated as the sum of each individual testcase's `time`, but that doesn't account for setup and teardown. Similarly, total time for all testsuites should be the amount of time between the `start` and `end` events, which the `Base` reporter stores in `stats.duration` for us. Fixes michaelleeallen#114
f49aff2
to
d2770c2
Compare
|
||
this._runner.on('suite', function(suite) { | ||
// allow tests to mock _onSuiteBegin | ||
return this._onSuiteBegin(suite); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests do this yet, but added for symmetry with _onSuiteEnd.
@clayreimann This is ready whenever you have a chance. |
The
time
attribute ontestsuite
should equal the amount of timebetween the runner issuing the
suite
andend suite
events.It was previously calculated as the sum of each individual testcase's
time
, but that doesn't account for setup and teardown.Similarly, total time for all testsuites should be the amount of
time between the
start
andend
events, which theBase
reporterstores in
stats.duration
for us.Fixes #114