-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(browser): ensure setup files are re-evaluated on each test run (fixes #8883) #8884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sheremet-va
merged 4 commits into
vitest-dev:main
from
yjaaidi:fix-isolate-and-setup-file
Oct 31, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7d6e4b2
test(browser): add failing test for re-evaluating setupFiles on each …
yjaaidi 298884d
fix(browser): ensure setup files are re-evaluated on each test run (f…
yjaaidi 8c377f4
test(browser): enhance test by checking output
yjaaidi 0593ade
test(browser): reorder expectations in runner test for debug clarity
yjaaidi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,7 +257,9 @@ export function createBrowserRunner( | |
|
|
||
| importFile = async (filepath: string, mode: 'collect' | 'setup') => { | ||
| let hash = this.hashMap.get(filepath) | ||
| if (!hash) { | ||
|
|
||
| // if the mode is setup, we need to re-evaluate the setup file on each test run | ||
| if (mode === 'setup' || !hash) { | ||
| hash = Date.now().toString() | ||
| this.hashMap.set(filepath, hash) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given we want to cache bust, is it useful to populate the hashMap when mode is |
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { expect, test } from 'vitest' | ||
| import { counter } from './counter' | ||
|
|
||
| test('increment counter', () => { | ||
| counter.increment() | ||
| expect(counter.get()).toBe(1) | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { expect, test } from 'vitest' | ||
| import { counter } from './counter' | ||
|
|
||
| test('make sure the counter is reset by the setup file beforeEach hook', () => { | ||
| counter.increment() | ||
| expect(counter.get()).toBe(1) | ||
| }); |
4 changes: 4 additions & 0 deletions
4
test/browser/fixtures/isolate-and-setup-file/browser-setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { beforeEach } from 'vitest' | ||
| import { counter } from './counter' | ||
|
|
||
| beforeEach(() => counter.reset()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const g = globalThis as unknown as { counter: number }; | ||
| export const counter = { | ||
| get: () => g.counter, | ||
| increment: () => g.counter++, | ||
| reset: () => (g.counter = 0), | ||
| }; |
17 changes: 17 additions & 0 deletions
17
test/browser/fixtures/isolate-and-setup-file/vitest.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { fileURLToPath } from 'node:url' | ||
| import { defineConfig } from 'vitest/config' | ||
| import { instances, provider } from '../../settings' | ||
|
|
||
| export default defineConfig({ | ||
| cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)), | ||
| test: { | ||
| setupFiles: ['./browser-setup.ts'], | ||
| browser: { | ||
| enabled: true, | ||
| isolate: false, | ||
| provider, | ||
| instances, | ||
| headless: false, | ||
| }, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the right way but I tried to keep the change minimalistic.