diff --git a/packages/runner/src/run.ts b/packages/runner/src/run.ts index b33ed3153c173..46b7fe795ae65 100644 --- a/packages/runner/src/run.ts +++ b/packages/runner/src/run.ts @@ -328,7 +328,7 @@ export async function runSuite(suite: Suite, runner: VitestRunner) { } if (suite.mode === 'run') { - if (!hasTests(suite)) { + if (!runner.config.passWithNoTests && !hasTests(suite)) { suite.result.state = 'fail' if (!suite.result.errors?.length) { const error = processError(new Error(`No test found in suite ${suite.name}`)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e5c95f8048c5e..a3e3ae6cfe4ee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1618,6 +1618,12 @@ importers: specifier: workspace:* version: link:../../packages/vitest + test/empty-test: + devDependencies: + vitest: + specifier: workspace:* + version: link:../../packages/vitest + test/env-custom: devDependencies: '@types/debug': diff --git a/test/empty-test/package.json b/test/empty-test/package.json new file mode 100644 index 0000000000000..37af68d324f3d --- /dev/null +++ b/test/empty-test/package.json @@ -0,0 +1,11 @@ +{ + "name": "@vitest/test-empty-test", + "type": "module", + "private": true, + "scripts": { + "test": "vitest run --passWithNoTests" + }, + "devDependencies": { + "vitest": "workspace:*" + } +} diff --git a/test/empty-test/test/empty.test.ts b/test/empty-test/test/empty.test.ts new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/test/empty-test/test/one.test.ts b/test/empty-test/test/one.test.ts new file mode 100644 index 0000000000000..c68d89ac3c7cb --- /dev/null +++ b/test/empty-test/test/one.test.ts @@ -0,0 +1,3 @@ +import { expect, test } from 'vitest' + +test('two', () => expect(1 + 1).toBe(2)) diff --git a/test/empty-test/vitest.config.ts b/test/empty-test/vitest.config.ts new file mode 100644 index 0000000000000..abed6b2116e14 --- /dev/null +++ b/test/empty-test/vitest.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({})