Skip to content

Commit

Permalink
fix(browser): use correct project when filtering entries in the bro…
Browse files Browse the repository at this point in the history
…wser mode (#7167)
  • Loading branch information
sheremet-va authored Jan 8, 2025
1 parent 8dd2071 commit 423d634
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
name: 'vitest:browser:tests',
enforce: 'pre',
async config() {
const project = parentServer.vitest.getProjectByName(parentServer.config.name)
// this plugin can be used in different projects, but all of them
// have the same `include` pattern, so it doesn't matter which project we use
const project = parentServer.project
const { testFiles: allTestFiles } = await project.globTestFiles()
const browserTestFiles = allTestFiles.filter(
file => getFilePoolName(project, file) === 'browser',
Expand Down
12 changes: 11 additions & 1 deletion test/browser/specs/runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import type { Vitest } from 'vitest/node'
import type { JsonTestResults } from 'vitest/reporters'
import { readFile } from 'node:fs/promises'
import { beforeAll, describe, expect, onTestFailed, test } from 'vitest'
import { instances, provider, runBrowserTests } from './utils'

describe('running browser tests', async () => {
let stderr: string
let stdout: string
let browserResultJson: any
let browserResultJson: JsonTestResults
let passedTests: any[]
let failedTests: any[]
let vitest: Vitest

beforeAll(async () => {
({
stderr,
stdout,
ctx: vitest,
} = await runBrowserTests())

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

const testFiles = browserResultJson.testResults.map(t => t.name)

// test files are optimized automatically
expect(vitest.projects.map(p => p.browser?.vite.config.optimizeDeps.entries))
.toEqual(vitest.projects.map(() => expect.arrayContaining(testFiles)))

// This should match the number of actual tests from browser.json
// if you added new tests, these assertion will fail and you should
// update the numbers
Expand Down

0 comments on commit 423d634

Please sign in to comment.