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

Keep time attribute in JUnit XML file #1825

Closed
6 tasks done
linbudu599 opened this issue Aug 9, 2022 · 0 comments · Fixed by #1842
Closed
6 tasks done

Keep time attribute in JUnit XML file #1825

linbudu599 opened this issue Aug 9, 2022 · 0 comments · Fixed by #1842

Comments

@linbudu599
Copy link

linbudu599 commented Aug 9, 2022

Describe the bug

Currently in junit reporter, when task.result.duration's value is 0, the duration got undefined as fallback value by JavaScript's implicit conversion, which results in that generated report file will not got time attribute in <testcase> tag.

function getDuration(task: Task): string | undefined {
  return task.result?.duration ? (task.result.duration / 1000).toFixed(10) : undefined
}

The produced xml file:

<testsuites id="" name="" tests="1" failures="0" skipped="0" errors="0" time="0.014961999997496605">
  <testsuite name="x" timestamp="2022-08-09T09:17:24.527Z" hostname="" tests="5" failures="0" errors="0" skipped="0" time="0.0070000000">
    <!-- no time attribute was present -->
    <testcase classname="x" name="should xxx">
    </testcase>
  </testsuite>
</testsuites>

In junit standard, time attribute should be kept even using value '0'. Also, this will cause some tools work incorrectly.

Use 0 as fallback value should fix this:

function getDuration(task: Task): string {
  return typeof task.result?.duration === 'number' ? task.result.duration === 0 ? '0' : (task.result.duration / 1000).toFixed(10) : '0'
}

Reproduction

I'm not sure why the task.result.duration reveived value 0, but in some simple test cases(e.g. only one expect statement) it always appear, so I suspect that this is also a precision loss problem caused by JavaScript.

System Info

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1
    Memory: 90.95 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 8.10.0 - ~/.nvm/versions/node/v14.17.4/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
    Edge: 104.0.1293.47
    Firefox: 89.0.2
    Safari: 15.4

Used Package Manager

npm

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants