vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Junit reporter does not escape error messages and stacktraces

Open flunderpero opened this issue 3 years ago • 1 comments

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 &apos;&apos; to be &apos;English Title&apos; // 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

flunderpero avatar Aug 08 '22 17:08 flunderpero

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.

flunderpero avatar Aug 09 '22 11:08 flunderpero