Skip to content
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

Merged

Conversation

gabegorelick
Copy link
Contributor

@gabegorelick gabegorelick commented May 9, 2020

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 #114

@@ -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;
Copy link
Contributor Author

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(),
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

@gabegorelick gabegorelick force-pushed the setup-teardown-time branch from 13bd5dc to f49aff2 Compare May 9, 2020 03:08
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
@gabegorelick gabegorelick force-pushed the setup-teardown-time branch from f49aff2 to d2770c2 Compare June 20, 2020 16:33

this._runner.on('suite', function(suite) {
// allow tests to mock _onSuiteBegin
return this._onSuiteBegin(suite);
Copy link
Contributor Author

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.

@gabegorelick
Copy link
Contributor Author

@clayreimann This is ready whenever you have a chance.

@michaelleeallen michaelleeallen added the bugfix fixes an issue label Dec 18, 2020
@michaelleeallen michaelleeallen merged commit 18ff0f4 into michaelleeallen:master Dec 18, 2020
@gabegorelick gabegorelick deleted the setup-teardown-time branch December 18, 2020 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testsuite time does not include setup or teardown
2 participants