Skip to content

Commit

Permalink
fix: forceRerunTriggers correctly triggers a rerun (#3829)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jul 28, 2023
1 parent 280e674 commit 17988e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const trigger = false
4 changes: 4 additions & 0 deletions test/watch/fixtures/vitest.config.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 17988e5

Please sign in to comment.