Skip to content

Commit 423d634

Browse files
authored
fix(browser): use correct project when filtering entries in the browser mode (#7167)
1 parent 8dd2071 commit 423d634

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/browser/src/node/plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
152152
name: 'vitest:browser:tests',
153153
enforce: 'pre',
154154
async config() {
155-
const project = parentServer.vitest.getProjectByName(parentServer.config.name)
155+
// this plugin can be used in different projects, but all of them
156+
// have the same `include` pattern, so it doesn't matter which project we use
157+
const project = parentServer.project
156158
const { testFiles: allTestFiles } = await project.globTestFiles()
157159
const browserTestFiles = allTestFiles.filter(
158160
file => getFilePoolName(project, file) === 'browser',

test/browser/specs/runner.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import type { Vitest } from 'vitest/node'
2+
import type { JsonTestResults } from 'vitest/reporters'
13
import { readFile } from 'node:fs/promises'
24
import { beforeAll, describe, expect, onTestFailed, test } from 'vitest'
35
import { instances, provider, runBrowserTests } from './utils'
46

57
describe('running browser tests', async () => {
68
let stderr: string
79
let stdout: string
8-
let browserResultJson: any
10+
let browserResultJson: JsonTestResults
911
let passedTests: any[]
1012
let failedTests: any[]
13+
let vitest: Vitest
1114

1215
beforeAll(async () => {
1316
({
1417
stderr,
1518
stdout,
19+
ctx: vitest,
1620
} = await runBrowserTests())
1721

1822
const browserResult = await readFile('./browser.json', 'utf-8')
@@ -28,6 +32,12 @@ describe('running browser tests', async () => {
2832
console.error(stderr)
2933
})
3034

35+
const testFiles = browserResultJson.testResults.map(t => t.name)
36+
37+
// test files are optimized automatically
38+
expect(vitest.projects.map(p => p.browser?.vite.config.optimizeDeps.entries))
39+
.toEqual(vitest.projects.map(() => expect.arrayContaining(testFiles)))
40+
3141
// This should match the number of actual tests from browser.json
3242
// if you added new tests, these assertion will fail and you should
3343
// update the numbers

0 commit comments

Comments
 (0)