Junit reporter does not escape error messages and stacktraces
Describe the bug
The Junit reporter produces illegal XML if something resembling an XML tag shows up in the error message or stack trace.
As an example, we get this Junit-XML which is clearly malformed:
<testcase classname="packages/server.faas.scrape/__tests__/scrape_basics.spec.ts" name="Extract title from title tag" time="3.3660000000">
<failure message="expected '' to be 'English Title' // Object.is equality" type="AssertionError">
AssertionError: expected '' to be 'English Title' // Object.is equality
❯ test_function packages/server.faas.scrape/__tests__/scrape_basics.spec.ts:26:30
❯ Server.<anonymous> packages/lib.shared.test/fixtures.ts:16:16
</failure>
</testcase>
The string <anonymous> should be escaped.
Reproduction
See the following Stackblitz for an example of a test that produces malformed XML:
https://stackblitz.com/edit/vitest-dev-vitest-b4w9ta?file=test/basic.test.ts
System Info
System:
OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Xeon(R) CPU @ 2.20GHz
Memory: 2.61 GB / 3.84 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 18.7.0 - /usr/bin/node
Yarn: 3.1.0 - /usr/bin/yarn
npm: 8.15.0 - /usr/bin/npm
npmPackages:
vitest: 0.21.0 => 0.21.0
Used Package Manager
yarn
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
I am trying to create a PR but I cannot get the reporters test suite to run. Running vitest run test/reporters gives
No test suite found in file test/reporters/tests/reporters.spec.ts
Am I missing something? And another question: Would it be ok / desirable if I modified test/reporters/src/data.ts to include an error with invalid XML syntax or should I build up my own files in the test case I am writing? I am fine with both.