From 8d183da4f7cc2986d11c802d16bacd221fb69b96 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Tue, 28 Nov 2023 20:39:41 +0800 Subject: [PATCH] fix(runner): passWithNoTests option not work (#4553) --- packages/runner/src/run.ts | 2 +- pnpm-lock.yaml | 6 ++++++ test/empty-test/package.json | 11 +++++++++++ test/empty-test/test/empty.test.ts | 0 test/empty-test/test/one.test.ts | 3 +++ test/empty-test/vitest.config.ts | 3 +++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/empty-test/package.json create mode 100644 test/empty-test/test/empty.test.ts create mode 100644 test/empty-test/test/one.test.ts create mode 100644 test/empty-test/vitest.config.ts diff --git a/packages/runner/src/run.ts b/packages/runner/src/run.ts index b33ed3153c17..46b7fe795ae6 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 e5c95f8048c5..a3e3ae6cfe4e 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 000000000000..37af68d324f3 --- /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 000000000000..e69de29bb2d1 diff --git a/test/empty-test/test/one.test.ts b/test/empty-test/test/one.test.ts new file mode 100644 index 000000000000..c68d89ac3c7c --- /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 000000000000..abed6b2116e1 --- /dev/null +++ b/test/empty-test/vitest.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({})