Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export abstract class BaseReporter implements Reporter {
}

onWatcherStart(files: File[] = this.ctx.state.getFiles(), errors: unknown[] = this.ctx.state.getUnhandledErrors()): void {
const failed = errors.length > 0 || hasFailed(files)
const failed = errors.length > 0 || hasFailed(files) || this.failedUnwatchedFiles.length > 0

if (failed) {
this.log(withLabel('red', 'FAIL', 'Tests failed. Watching for file changes...'))
Expand Down
18 changes: 17 additions & 1 deletion test/e2e/test/watch/reporter-failed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ describe.for([
fs.editFile('./basic.test.js', code => `${code}\n`)

await vitest.waitForStdout('RERUN ../basic.test.js')
await vitest.waitForStdout('Waiting for file changes...')
await vitest.waitForStdout('Tests failed. Watching for file changes...')

expect(vitest.stdout).not.toContain('log fail')
expect(vitest.stdout).toContain('❯ failed.test.js')
expect(vitest.stdout).toContain('× fails')
expect(vitest.stdout).toContain('1 failed')
expect(vitest.stdout).toContain('1 passed')
expect(vitest.stdout).not.toContain('PASS Waiting for file changes')
})

it('returns to PASS once the failing file is fixed', async () => {
const { vitest, fs } = await runReporterTests(isTTY)

expect(vitest.stdout).toContain('1 failed')

vitest.resetOutput()

fs.editFile('./failed.test.js', code => code.replace('throw new Error(\'failed\')', ''))

await vitest.waitForStdout('RERUN ../failed.test.js')
await vitest.waitForStdout('PASS Waiting for file changes...')

expect(vitest.stdout).not.toContain('1 failed')
})

it('prints tests once if changed test is the same', async () => {
Expand Down
Loading