-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(runner): mark tests as failed when beforeAll/afterAll
failed
#4799
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { afterAll, afterEach, beforeAll, beforeEach, describe, it } from 'vitest' | ||
|
||
describe("fail beforeEach", () => { | ||
beforeEach(() => { | ||
throw new Error("fail"); | ||
}); | ||
|
||
it("run", () => {}); | ||
it.skip("skip", () => {}); | ||
}) | ||
|
||
describe("fail beforeAll", () => { | ||
beforeAll(() => { | ||
throw new Error("fail"); | ||
}); | ||
|
||
it("run", () => {}); | ||
it.skip("skip", () => {}); | ||
}) | ||
|
||
describe("fail afterEach", () => { | ||
afterEach(() => { | ||
throw new Error("fail"); | ||
}); | ||
|
||
it("run", () => {}); | ||
it.skip("skip", () => {}); | ||
}) | ||
|
||
describe("fail afterAll", () => { | ||
afterAll(() => { | ||
throw new Error("fail"); | ||
}); | ||
|
||
it("run", () => {}); | ||
it.skip("skip", () => {}); | ||
}) | ||
|
||
it("ok", () => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like doing this for every test because the terminal seems bloated. We have a
suite.result
and it's enough. I think reporters should handle this case if they don't distinguish between suite fails and test failsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds fair. To explain my perspective, the reason I went with this is that I thought
beforeAll/afterAll
failures should be more aligned withbeforeEach/afterEach
failures.I experimented with current behavior on stackblitz:
https://stackblitz.com/edit/vitest-dev-vitest-m7bw4w?file=test%2Frepro.test.ts
Vitest UI screenshot
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":
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 haveskip
state ifbeforeAll
failed (because we don't run any test), and any state ifafterAll
failed (only the suite is marked as failed)afterAll
fails only a suite which seems correct to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with
mocha
for example: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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!