testsuite time does not include setup or teardown
gabegorelick opened this issue · comments
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:
Lines 404 to 413 in 94016cc
PR: #115