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 does not include setup or teardown #114

Closed
gabegorelick opened this issue May 8, 2020 · 1 comment · Fixed by #115
Closed

testsuite time does not include setup or teardown #114

gabegorelick opened this issue May 8, 2020 · 1 comment · Fixed by #115
Labels

Comments

@gabegorelick
Copy link
Contributor

It looks like testsuite (and testsuites) is calculating the time attribute by summing the time each testcase took. However, this ignores the amount of time that setup and teardown take.

Example test:

describe('suite', function () {
  before(done => setTimeout(done, 1000));

  it('should complete immediately', () => {});
});

Mocha's spec and xunit reporters correctly output that this suite took 1s. Here's the xunit output for example:

<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Fri, 08 May 2020 17:33:39 GMT" time="1.008">
<testcase classname="suite" name="should complete immediately" time="0"/>
</testsuite>

However, mocha-junit-reporter incorrectly reports that the entire testsuite took 0s:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" time="0.0000" tests="1" failures="0">
  <testsuite name="Root Suite" timestamp="2020-05-08T17:30:12" tests="0" time="0.0000" failures="0">
  </testsuite>
  <testsuite name="suite" timestamp="2020-05-08T17:30:12" tests="1" file="test.js" time="0.0000" failures="0">
    <testcase name="suite should complete immediately" time="0.0000" classname="example test">
    </testcase>
  </testsuite>
</testsuites>

Relevant code:

var suiteTime = 0;
_cases.forEach(function(testcase) {
var lastNode = testcase.testcase[testcase.testcase.length - 1];
_suiteAttr.skipped += Number('skipped' in lastNode);
_suiteAttr.failures += Number('failure' in lastNode);
suiteTime += testcase.testcase[0]._attr.time;
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(4);
});
_suiteAttr.time = suiteTime.toFixed(4);

gabegorelick added a commit to gabegorelick/mocha-junit-reporter that referenced this issue May 9, 2020
The `time` attribute on `testsuite` should equal the amount of time
between the runner issuing the `suite start` and `suite end` 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
Copy link
Contributor Author

PR: #115

gabegorelick added a commit to gabegorelick/mocha-junit-reporter that referenced this issue 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 michaelleeallen#114
gabegorelick added a commit to gabegorelick/mocha-junit-reporter that referenced this issue Jun 20, 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 michaelleeallen#114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants