-
-
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
Changes from 2 commits
7d6e4b2
298884d
8c377f4
0593ade
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
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 |
||
| } | ||
|
|
||
| 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) | ||
| }); |
| 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) | ||
| }); |
| 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()) |
| 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), | ||
| }; |
| 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, | ||
| }, | ||
| }, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,6 +290,13 @@ test('in-source tests run correctly when filtered', async () => { | |
| expect(stdout).toContain(`Tests ${instances.length} passed`) | ||
| }) | ||
|
|
||
| test('re-evaluate setupFiles on each test run even when isolate is false', async () => { | ||
| const { exitCode } = await runBrowserTests({ | ||
| root: './fixtures/isolate-and-setup-file', | ||
| }) | ||
| expect(exitCode).toBe(0) | ||
|
||
| }) | ||
|
|
||
| test.runIf(provider.name === 'playwright')('timeout hooks', async ({ onTestFailed }) => { | ||
| const { stderr } = await runBrowserTests({ | ||
| root: './fixtures/timeout-hooks', | ||
|
|
||
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.