From e256152c1d6142600cecf3651d055b8ca6ad1153 Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Sat, 24 Feb 2024 14:46:20 +0200 Subject: [PATCH] fix(workspace): throw error when browser mode and `@vitest/coverage-v8` are used --- packages/vitest/src/node/workspace.ts | 11 +++++++++-- .../workspace/browser/workspace-with-browser.ts | 13 +++++++++++++ test/config/test/failures.test.ts | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/config/fixtures/workspace/browser/workspace-with-browser.ts diff --git a/packages/vitest/src/node/workspace.ts b/packages/vitest/src/node/workspace.ts index a18a438b87ac..0a973f9f00e6 100644 --- a/packages/vitest/src/node/workspace.ts +++ b/packages/vitest/src/node/workspace.ts @@ -297,7 +297,15 @@ export class WorkspaceProject { } async setServer(options: UserConfig, server: ViteDevServer) { - this.config = resolveConfig(this.ctx.mode, options, server.config) + this.config = resolveConfig( + this.ctx.mode, + { + ...options, + coverage: this.ctx.config.coverage, + }, + server.config, + ) + this.server = server this.vitenode = new ViteNodeServer(server, this.config.server) @@ -329,7 +337,6 @@ export class WorkspaceProject { return deepMerge({ ...this.config, - coverage: this.ctx.config.coverage, poolOptions: { forks: { diff --git a/test/config/fixtures/workspace/browser/workspace-with-browser.ts b/test/config/fixtures/workspace/browser/workspace-with-browser.ts new file mode 100644 index 000000000000..993a69926b3f --- /dev/null +++ b/test/config/fixtures/workspace/browser/workspace-with-browser.ts @@ -0,0 +1,13 @@ +import { defineWorkspace } from "vitest/config"; + +export default defineWorkspace([ + { + test: { + name: "Browser project", + browser: { + enabled: true, + name: 'chrome' + }, + } + } +]) \ No newline at end of file diff --git a/test/config/test/failures.test.ts b/test/config/test/failures.test.ts index e9c4d8300af6..0007f55aac3f 100644 --- a/test/config/test/failures.test.ts +++ b/test/config/test/failures.test.ts @@ -61,6 +61,12 @@ test('v8 coverage provider cannot be used with browser', async () => { expect(stderr).toMatch('Error: @vitest/coverage-v8 does not work with --browser. Use @vitest/coverage-istanbul instead') }) +test('v8 coverage provider cannot be used with browser in workspace', async () => { + const { stderr } = await runVitest({ coverage: { enabled: true }, workspace: './fixtures/workspace/browser/workspace-with-browser.ts' }) + + expect(stderr).toMatch('Error: @vitest/coverage-v8 does not work with --browser. Use @vitest/coverage-istanbul instead') +}) + test('version number is printed when coverage provider fails to load', async () => { const { stderr, stdout } = await runVitest({ coverage: {