Skip to content
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: forceRerunTriggers correctly triggers a rerun #3829

Merged
merged 1 commit into from Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -644,7 +644,7 @@ export class Vitest {

if (mm.isMatch(id, this.config.forceRerunTriggers)) {
this.state.getFilepaths().forEach(file => this.changedTests.add(file))
return []
return [id]
}

const projects = this.getModuleProjects(id)
Expand Down
1 change: 1 addition & 0 deletions test/watch/fixtures/force-watch/trigger.js
@@ -0,0 +1 @@
export const trigger = false
4 changes: 4 additions & 0 deletions test/watch/fixtures/vitest.config.ts
Expand Up @@ -10,5 +10,9 @@ export default defineConfig({

// This configuration is edited by tests
reporters: 'verbose',

forceRerunTriggers: [
'**/force-watch/**',
],
},
})
16 changes: 16 additions & 0 deletions test/watch/test/file-watching.test.ts
Expand Up @@ -12,6 +12,9 @@ const testFileContent = readFileSync(testFile, 'utf-8')
const configFile = 'fixtures/vitest.config.ts'
const configFileContent = readFileSync(configFile, 'utf-8')

const forceTriggerFile = 'fixtures/force-watch/trigger.js'
const forceTriggerFileContent = readFileSync(forceTriggerFile, 'utf-8')

const cliArgs = ['--root', 'fixtures', '--watch']
const cleanups: (() => void)[] = []

Expand All @@ -26,6 +29,7 @@ afterEach(() => {
writeFileSync(sourceFile, sourceFileContent, 'utf8')
writeFileSync(testFile, testFileContent, 'utf8')
writeFileSync(configFile, configFileContent, 'utf8')
writeFileSync(forceTriggerFile, forceTriggerFileContent, 'utf8')
cleanups.splice(0).forEach(cleanup => cleanup())
})

Expand All @@ -39,6 +43,18 @@ test('editing source file triggers re-run', async () => {
await vitest.waitForStdout('1 passed')
})

test('editing force rerun trigger reruns all tests', async () => {
const vitest = await runVitestCli(...cliArgs)

writeFileSync(forceTriggerFile, editFile(forceTriggerFileContent), 'utf8')

await vitest.waitForStdout('Waiting for file changes...')
await vitest.waitForStdout('RERUN ../force-watch/trigger.js')
await vitest.waitForStdout('example.test.ts')
await vitest.waitForStdout('math.test.ts')
await vitest.waitForStdout('2 passed')
})

test('editing test file triggers re-run', async () => {
const vitest = await runVitestCli(...cliArgs)

Expand Down