Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/browser/src/client/tester/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

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.

hash = Date.now().toString()
this.hashMap.set(filepath, hash)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 setup?

}
Expand Down
7 changes: 7 additions & 0 deletions test/browser/fixtures/isolate-and-setup-file/a.test.ts
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)
});
7 changes: 7 additions & 0 deletions test/browser/fixtures/isolate-and-setup-file/b.test.ts
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 test/browser/fixtures/isolate-and-setup-file/browser-setup.ts
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())
6 changes: 6 additions & 0 deletions test/browser/fixtures/isolate-and-setup-file/counter.ts
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 test/browser/fixtures/isolate-and-setup-file/vitest.config.ts
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,
},
},
})
7 changes: 7 additions & 0 deletions test/browser/specs/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a check similar to line 284 that confirms the file actually did run

Copy link
Contributor Author

@yjaaidi yjaaidi Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ done

Oh! I didn't notice the who instances settings. Good to know 😊
Btw, expect.soft sounds like a better fit for failure analysis here. (I mean in these kind of exitCode + outputs checks)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. We usually keep the error check first instead of the exitCode for that reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

})

test.runIf(provider.name === 'playwright')('timeout hooks', async ({ onTestFailed }) => {
const { stderr } = await runBrowserTests({
root: './fixtures/timeout-hooks',
Expand Down
Loading