Skip to content
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

fix(browser): use correct project when filtering entries in the browser mode #7167

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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/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
Loading