-
-
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(core): test change should trigger failed test rerun #3773
Draft
btea
wants to merge
7
commits into
vitest-dev:main
Choose a base branch
from
btea:fix/test-change-trigger-rerun-fail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43d9d1c
fix(core): test change should trigger failed test rerun
btea 1596d97
fix: lint
btea 67617fd
fix: add isFailedModel & test
btea 0d017c1
chore: fix lint
btea 9419398
Merge branch 'main' into fix/test-change-trigger-rerun-fail
btea f15d3b4
chore: fix lint
btea df0d771
chore: fix lint
btea 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 |
---|---|---|
|
@@ -94,6 +94,37 @@ test('2 - test that is cancelled', async () => { | |
}) | ||
}) | ||
|
||
test('rerun failed tests', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need a test case that fails in Maybe something like below? test('rerun failed tests', async () => {
const testPath = 'fixtures/error.test.ts'
const failAssertion = 'expect(1).toBe(2)'
const testCase = `// Dynamic test case
import { test, expect } from 'vitest'
// Failure re-run should run this
test('failing test', () => {
${failAssertion}
})
// Failure re-run should NOT run this
test('passing test', () => {
expect(1).toBe(1)
})
`
writeFileSync(testPath, testCase, 'utf8')
cleanups.push(() => rmSync(testPath))
const vitest = await runVitestCli(...cliArgs)
await vitest.waitForStdout('Test Files 1 failed | 2 passed (3)')
await vitest.waitForStdout('Tests 1 failed | 3 passed (4)')
// Re-run failed tests only
vitest.write('f')
// Only a single test should have run
await vitest.waitForStdout('Test Files 1 failed (1)')
// Only a single test case should have run
await vitest.waitForStdout('Tests 1 failed (1)')
// Fix failing test case
writeFileSync(testPath, testCase.replace(failAssertion, ''), 'utf8')
// Only the previously failed test file should run
await vitest.waitForStdout('Test Files 1 pass (1)')
// Only the previously failed test case should run
await vitest.waitForStdout('Tests 1 pass (1)')
}) |
||
const { vitest } = await runVitest({ ..._options }) | ||
const testPath = 'fixtures/error.test.ts' | ||
const testCase = ` | ||
import { test, expect } from 'vitest' | ||
test('fail test', () => { | ||
expect(1).toBe(2) | ||
}) | ||
` | ||
const testTwoPath = 'fixtures/normal.test.ts' | ||
const testTwoCase = ` | ||
import { test, expect } from 'vitest' | ||
test('normal test', () => { | ||
expect(1).toBe(1) | ||
}) | ||
` | ||
writeFileSync(testPath, testCase, 'utf8') | ||
writeFileSync(testTwoPath, testTwoCase, 'utf8') | ||
|
||
await vitest.waitForStdout('1 failed') | ||
|
||
writeFileSync(testTwoPath, testCase.replace(/1/g, '2'), 'utf8') | ||
await vitest.waitForStdout('1 pass') | ||
|
||
vitest.write('f') | ||
await vitest.waitForStdout('1 failed') | ||
|
||
writeFileSync(testTwoPath, testCase.replace(/2/g, '3'), 'utf8') | ||
await vitest.waitForStdout('1 failed') | ||
}) | ||
|
||
test('rerun current pattern tests', async () => { | ||
const { vitest } = await runVitest({ ..._options, testNamePattern: 'sum' }) | ||
|
||
|
Oops, something went wrong.
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 think we should set properties of
ctx
outside it like this. Could this filter be toggled on/off inside thecore.ts
instead?But your approach is right in the way that we indeed need to save the failure filter in state.