Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/vitest/src/node/test-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ export class TestRun {

assert(task && entity, `Entity must be found for task ${task?.name || id}`)

if (event === 'suite-failed-early' && entity.type === 'module') {
// the file failed during import
await this.vitest.report('onTestModuleStart', entity)
await this.vitest.report('onTestModuleEnd', entity)
return
}

if (event === 'suite-prepare' && entity.type === 'suite') {
return await this.vitest.report('onTestSuiteReady', entity)
}
Expand Down
34 changes: 34 additions & 0 deletions test/cli/test/fails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,37 @@ it('prints a warning if the assertion is not awaited in the browser mode', async
expect(stderr).toContain('Promise returned by \`expect(actual).resolves.toBe(expected)\` was not awaited')
expect(stderr).toContain('base.test.js:5:33')
})

it('reports test file if it failed to load', async () => {
const hooks: string[] = []
await runInlineTests({
'basic.test.js': `throw new Error('fail')`,
}, {
reporters: [
'default',
{
onTestModuleQueued(testModule) {
hooks.push(`onTestModuleQueued:${testModule.relativeModuleId}`)
},
onTestModuleStart(testModule) {
hooks.push(`onTestModuleStart:${testModule.relativeModuleId}`)
},
onTestModuleCollected(testModule) {
hooks.push(`onTestModuleCollected:${testModule.relativeModuleId}`)
},
onTestModuleEnd(testModule) {
hooks.push(`onTestModuleEnd:${testModule.relativeModuleId}`)
},
},
],
})

expect(hooks).toMatchInlineSnapshot(`
[
"onTestModuleQueued:basic.test.js",
"onTestModuleCollected:basic.test.js",
"onTestModuleStart:basic.test.js",
"onTestModuleEnd:basic.test.js",
]
`)
})
Loading