Skip to content

Commit

Permalink
fix(workspace): throw error when browser mode and `@vitest/coverage-v…
Browse files Browse the repository at this point in the history
…8` are used
  • Loading branch information
AriPerkkio committed Feb 26, 2024
1 parent 5bb8b38 commit e256152
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -329,7 +337,6 @@ export class WorkspaceProject {

return deepMerge({
...this.config,
coverage: this.ctx.config.coverage,

poolOptions: {
forks: {
Expand Down
13 changes: 13 additions & 0 deletions test/config/fixtures/workspace/browser/workspace-with-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineWorkspace } from "vitest/config";

export default defineWorkspace([
{
test: {
name: "Browser project",
browser: {
enabled: true,
name: 'chrome'
},
}
}
])
6 changes: 6 additions & 0 deletions test/config/test/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit e256152

Please sign in to comment.