diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index f8ea2f90d..cd2963bad 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -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: [] } } diff --git a/test/e2e/test/__snapshots__/list.test.ts.snap b/test/e2e/test/__snapshots__/list.test.ts.snap index dbec0325e..906ece589 100644 --- a/test/e2e/test/__snapshots__/list.test.ts.snap +++ b/test/e2e/test/__snapshots__/list.test.ts.snap @@ -19,6 +19,11 @@ Error: top level error " `; +exports[`basic output shows error with static parsing 1`] = ` +"Error: No test suite found in file /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 @@ -104,6 +109,11 @@ Error: top level error " `; +exports[`json output shows error with static parsing 1`] = ` +"Error: No test suite found in file /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 @@ -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 /fixtures/list/top-level-error.test.ts +" +`; diff --git a/test/e2e/test/list.test.ts b/test/e2e/test/list.test.ts index fe83e2d6f..98ba63744 100644 --- a/test/e2e/test/list.test.ts +++ b/test/e2e/test/list.test.ts @@ -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(`