Skip to content

Workspace setup for Node and Browser Test no longer working since Vitest 3.1.3 #7964

@kayahr

Description

@kayahr

Describe the bug

(This MIGHT be a duplicate of #7944 but the problem described there is very specific and hard to follow and may only be related and not the same)

Projects with Node and Browser Tests configured by a vitest.workspace.js config like this is no longer working:

import { defineWorkspace } from "vitest/config";

export default defineWorkspace([
    {
        extends: "./vitest.config.js",
        test: {
            name: "Node"
        }
    },
    {
        extends: "./vitest.config.js",
        test: {
            name: "Browser",
            browser: {
                enabled: true
            }
        }
    }
]);

Instead of running the tests once in Node and once in Browser the tests are now executed in Node twice and never in Browser. Looks like the test.browser.enabled: true flag in the workspace config is ignored.

Downgrading to Vitest 3.1.2 fixes the problem.

Reproduction

I created a minimal project for reproduction. It contains three test files. One must be executed in both environments, one only works in Node and one only works in Browser. All three output the useragent to the console to see where they are executed.

git clone https://github.com/kayahr/vitest-browser-bug
cd vitest-browser-bug
npm i
npm test

The debug logging shows:

check2 run in Node.js/22
check3 run in Node.js/22
check1 run in Node.js/22
check1 run in Node.js/22

So check1 was executed twice in Node and check3 (which must only be run in Browser) is also executed in Node. This results in test failure:

 FAIL   Browser  src/test/check3.browser.test.ts > this test must only be executed in browser
ReferenceError: document is not defined
 ❯ src/test/check3.browser.test.ts:5:12
      3| it("this test must only be executed in browser", () => {
      4|     console.log("check3 run in", navigator.userAgent);
      5|     expect(document).toBeDefined();
       |            ^
      6| });
      7| 

When downgrading vitest and @vitest/browser to 3.1.2 and run npm i and npm test again, everything works as expected

System Info

System:
    OS: Linux 6.14 Arch Linux
    CPU: (8) x64 AMD Ryzen 9 7950X3D 16-Core Processor
    Memory: 52.88 GB / 61.96 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 22.14.0 - /usr/bin/node
    npm: 11.3.0 - ~/.local/bin/npm
    pnpm: 10.10.0 - ~/.local/bin/pnpm
  Browsers:
    Chromium: 136.0.7103.92
  npmPackages:
    @vitest/browser: 3.1.3 => 3.1.3 
    playwright: 1.52.0 => 1.52.0 
    vitest: 3.1.3 => 3.1.3

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions