fix(runner): mark tests as failed when beforeAll/afterAll failed#4799
fix(runner): mark tests as failed when beforeAll/afterAll failed#4799hi-ogawa wants to merge 4 commits intovitest-dev:mainfrom
beforeAll/afterAll failed#4799Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 canceled.
|
beforeAll/afterAll failed
beforeAll/afterAll failedbeforeAll/afterAll failed
beforeAll/afterAll failedbeforeAll/afterAll failed
| } | ||
|
|
||
| function markTasksAsFailed(suite: Suite, errors: ErrorWithDiff[], runner: VitestRunner) { | ||
| for (const t of getTests(suite)) { |
There was a problem hiding this comment.
I don't like doing this for every test because the terminal seems bloated
That sounds fair. To explain my perspective, the reason I went with this is that I thought beforeAll/afterAll failures should be more aligned with beforeEach/afterEach failures.
I experimented with current behavior on stackblitz:
For example, currently afterAll failure would keep tests as success and I thought that's not an intended behavior.
To avoid cluttering terminal with a single error appearing in all tests, I think I could do something like this while still flagging tests as "fail":
t.result = {
...t.result,
// flag as "fail"
state: 'fail',
// but don't have to copy errors
// errors: [...t.result?.errors ?? [], ...errors],
}What do you think?
EDIT: actually I did this first, then I realized currently junit reporter checks task.result.errors to generate <failure> tags. So, if we went with this, we still require modifying around this code:
vitest/packages/vitest/src/node/reporters/junit.ts
Lines 185 to 188 in 039814b
Okay, I'll also experiment with approach to fix only on junit reporter side.
There was a problem hiding this comment.
To explain my perspective, the reason I went with this is that I thought
beforeAll/afterAllfailures should be more aligned withbeforeEach/afterEachfailures.
afterAll/beforeAll are not bound to any test, they are suite hooks. beforeEach/afterEach are test hooks. What I would expect is for tests to have skip state if beforeAll failed (because we don't run any test), and any state if afterAll failed (only the suite is marked as failed)
For example, currently afterAll failure would keep tests as success and I thought that's not an intended behavior.
afterAll fails only a suite which seems correct to me.
There was a problem hiding this comment.
afterAll fails only a suite which seems correct to me.
This is consistent with mocha for example:
import { test, after } from 'mocha'
after(() => {
throw new Error('after')
})
test('test', () => {})Although in mocha afterEach doesn't fail the test while in Vitest it does.
If we are making it consistent, then 1) this is definitely a breaking change, 2) we need to decide what is consistent
There was a problem hiding this comment.
afterAll/beforeAll are not bound to any test, they are suite hooks. beforeEach/afterEach are test hooks.
Totally good point. I didn't have that understanding.
Okay, I'll see what I can do with junit reporter only first. Probably I'll close this PR and create a new one.
Thanks again for the review!
|
I'll closed this PR in favor of #4819. Within the discussion, you mentioned #4799 (comment)
and I agree that makes sense. I'll raise a dedicated issue for this, so it'll be discussed and handled separately. |


Description
Closes #4516
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.