Repository navigation
Using test.concurrent causes test report to attribute console output incorrectly
#9267
Replies: 3 comments
|
Any hints on this? :) |
|
Reporters can't really tell concurrent tests apart here. It comes from how console output gets tagged, not from the junit reporter itself. When you call I reproduced it on 4.1.12 with 6 concurrent tests that each log once. In the junit file, C0βC3 have no output at all, C4 gets A couple of ways around it, depending on what you need: If the per-test output in the report matters (e.g. CI): run with If you want to keep concurrency: tag the output yourself using the test context: test.concurrent('my test', ({ task, expect }) => {
console.log(`[${task.name}] doing the thing`)
})The lines will still be grouped under the wrong testcase in the junit XML, but at least you can tell which test wrote them. Properly separating it would need per-test async context tracking (something like |
|
This is not a junit reporter issue β it's how (and where) Vitest decides which task console output belongs to. The specifics, verified against the source at 4.x: Where the misattribution actually happensWhen const id =
s?.current?.id ||
s?.current?.suite?.id ||
s.current?.file.id || // β the "output disappears from the report" case
getTaskIdByStack(s.config.root)That pointer is a single, worker-global Two details make your specific output reproducible rather than random:
And the "missing lines" you noticed: when a write happens while What to do about it
If you want it fixed upstreamThe natural improvement is for the console intercept to prefer a stack-derived task id (the (RagedPanda's note above matches this: it's a capture-time attribution limitation, not something any reporter can distinguish after the fact.) |
Uh oh!
There was an error while loading. Please reload this page.
Hi!
We are using Vitest in a larger project and I noticed that when using
test.concurrent, the resulting test report (we are usingjunitxml format) incorrectly attributes the console outputs to the respective tests. Some console output is even missing completely, however only from the test report file, we are also using thedefaultreporter, and when we pipe its console output to a file, we can see all console output (however also not attributed to the correct test).Are the test reporters supposed to handle
test.concurrent? Are we missing some setting that is needed for this to work?Reproduction is given below:
package.jsontsconfig.jsontest/concurrent.test.tsrunning
npx vitest run --reporter=default --reporter=junit --outputFile=reports/vitest.junit.xmlafternpm installshows the behavior. On my machine it results in the followingreports/vitest.junit.xmlSame for the machine of a colleague, so the output seems "deterministic" in that sense.
As you can see, some console output is attributed incorrectly to Test 4 in the
concurrentcases.Is this a (known) bug/limitation?
Thanks a lot!
All reactions