-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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 testThe 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.3Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.