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
3 changes: 3 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,9 @@ export class Vitest {
const testModules = await this.parseSpecifications(files, {
concurrency: options.staticParseConcurrency,
})
if (hasFailed(testModules.map(testModule => testModule.task))) {
process.exitCode = 1
}
return { testModules, unhandledErrors: [] }
}

Expand Down
15 changes: 15 additions & 0 deletions test/e2e/test/__snapshots__/list.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Error: top level error
"
`;
exports[`basic output shows error with static parsing 1`] = `
"Error: No test suite found in file <root>/fixtures/list/top-level-error.test.ts
"
`;
exports[`correctly outputs all tests with args: "--browser.enabled" 1`] = `
"[chromium] basic.test.ts > basic suite > inner suite > some test
[chromium] basic.test.ts > basic suite > inner suite > another test
Expand Down Expand Up @@ -104,6 +109,11 @@ Error: top level error
"
`;
exports[`json output shows error with static parsing 1`] = `
"Error: No test suite found in file <root>/fixtures/list/top-level-error.test.ts
"
`;
exports[`json with a file output shows error 1`] = `
"Error: describe error
❯ describe-error.test.ts:4:9
Expand All @@ -122,3 +132,8 @@ Error: top level error
"
`;
exports[`json with a file output shows error with static parsing 1`] = `
"Error: No test suite found in file <root>/fixtures/list/top-level-error.test.ts
"
`;
11 changes: 11 additions & 0 deletions test/e2e/test/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ test.each([
expect(exitCode).toBe(1)
})

test.each([
['basic'],
['json', '--json'],
['json with a file', '--json=./list.json'],
])('%s output shows error with static parsing', async (_, ...args) => {
const { stderr, stdout, exitCode } = await runVitestCli('list', '-r=./fixtures/list', '-c=fail.config.ts', ...args)
expect(stdout).toBe('')
expect(relative(stderr)).toMatchSnapshot()
expect(exitCode).toBe(1)
})

test('correctly outputs json', async () => {
const { stdout, exitCode } = await runVitestCli('list', '-r=./fixtures/list', '--json')
expect(relative(stdout)).toMatchInlineSnapshot(`
Expand Down
Loading