-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Open
Copy link
Labels
Description
Describe the bug
We have flaky test with vmThreads and this is reproducible with following commands. This runs two happy-dom tests with different @vitest-environment-options specified as file comment on vmThreads in single worker:
$ pnpm -C test/core test:vmThreads test/happy-dom --maxWorkers=1
...
DEV v4.0.15 /home/hiroshi/code/others/vitest/test/core
API started at http://localhost:3023/
✓ vmThreads test/happy-dom.test.ts (8 tests | 1 skipped) 5ms
❯ vmThreads test/happy-dom-custom.test.ts (2 tests | 2 failed) 4ms
× custom URL is changed to my-website:5435 3ms
× accepts custom environment options 1ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL vmThreads test/happy-dom-custom.test.ts:15:1 > custom URL is changed to my-website:5435
AssertionError: expected 'http://localhost:3000/' to be 'http://my-website:5435/' // Object.is equality
Expected: "http://my-website:5435/"
Received: "http://localhost:3000/"
❯ test/happy-dom-custom.test.ts:16:25
14|
15| it('custom URL is changed to my-website:5435', () => {
16| expect(location.href).toBe('http://my-website:5435/')
| ^
17| })
18|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯It appears that environment are not reset properly between test files when different environment options are specified in file comment.
vitest/test/core/test/happy-dom.test.ts
Lines 1 to 3 in fa34701
| /** | |
| * @vitest-environment happy-dom | |
| */ |
vitest/test/core/test/happy-dom-custom.test.ts
Lines 1 to 4 in fa34701
| /** | |
| * @vitest-environment happy-dom | |
| * @vitest-environment-options { "url": "http://my-website:5435", "settings": { "disableCSSFileLoading": true } } | |
| */ |
Reproduction
See above
System Info
System:
OS: Linux 6.17 Arch Linux
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
Memory: 21.54 GB / 31.05 GB
Container: Yes
Shell: 5.3.3 - /usr/bin/bash
Binaries:
Node: 22.21.1 - /home/hiroshi/.volta/tools/image/node/22.21.1/bin/node
npm: 10.9.4 - /home/hiroshi/.volta/tools/image/node/22.21.1/bin/npm
pnpm: 10.24.0 - /home/hiroshi/.volta/bin/pnpm
bun: 1.2.20 - /home/hiroshi/.local/bin/bun
Deno: 2.4.5 - /home/hiroshi/.local/bin/deno
Browsers:
Chromium: 142.0.7444.175
Firefox: 145.0.1
Firefox Developer Edition: 145.0.1
npmPackages:
@vitest/browser: workspace:* => 4.0.15
@vitest/coverage-istanbul: workspace:* => 4.0.15
@vitest/coverage-v8: workspace:* => 4.0.15
@vitest/ui: workspace:* => 4.0.15
vite: ^7.1.5 => 7.1.5
vitest: workspace:* => 4.0.15Used Package Manager
pnpm
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.