Skip to content

Commit 010fc55

Browse files
authored
fix(vitest): override config.include option with config.browser.instances[].include option if it is specified (#8260)
1 parent 058b781 commit 010fc55

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

packages/vitest/src/node/projects/resolveProjects.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ function cloneConfig(project: TestProject, { browser, ...config }: BrowserInstan
303303
...overrideConfig
304304
} = config
305305
const currentConfig = project.config.browser
306+
const clonedConfig = deepClone(project.config)
306307
return mergeConfig<any, any>({
307-
...deepClone(project.config),
308+
...clonedConfig,
308309
browser: {
309310
...project.config.browser,
310311
locators: locators
@@ -321,6 +322,10 @@ function cloneConfig(project: TestProject, { browser, ...config }: BrowserInstan
321322
providerOptions: config,
322323
instances: undefined, // projects cannot spawn more configs
323324
},
325+
// If there is no include or exclude or includeSource pattern in browser.instances[], we should use the that's pattern from the parent project
326+
include: (overrideConfig.include && overrideConfig.include.length > 0) ? [] : clonedConfig.include,
327+
exclude: (overrideConfig.exclude && overrideConfig.exclude.length > 0) ? [] : clonedConfig.exclude,
328+
includeSource: (overrideConfig.includeSource && overrideConfig.includeSource.length > 0) ? [] : clonedConfig.includeSource,
324329
// TODO: should resolve, not merge/override
325330
} satisfies ResolvedConfig, overrideConfig) as ResolvedConfig
326331
}

test/config/test/browser-configs.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,81 @@ test('coverage provider v8 works correctly in workspaced browser mode if instanc
234234
])
235235
})
236236

237+
test('browser instances with include/exclude/includeSource option override parent that patterns', async () => {
238+
const { projects } = await vitest({}, {
239+
include: ['**/*.global.test.{js,ts}', '**/*.shared.test.{js,ts}'],
240+
exclude: ['**/*.skip.test.{js,ts}'],
241+
includeSource: ['src/**/*.{js,ts}'],
242+
browser: {
243+
enabled: true,
244+
headless: true,
245+
instances: [
246+
{ browser: 'chromium' },
247+
{ browser: 'firefox', include: ['test/firefox-specific.test.ts'], exclude: ['test/webkit-only.test.ts', 'test/webkit-extra.test.ts'], includeSource: ['src/firefox-compat.ts'] },
248+
{ browser: 'webkit', include: ['test/webkit-only.test.ts', 'test/webkit-extra.test.ts'], exclude: ['test/firefox-specific.test.ts'], includeSource: ['src/webkit-compat.ts'] },
249+
],
250+
},
251+
})
252+
253+
// Chromium should inherit parent include/exclude/includeSource patterns (plus default test pattern)
254+
expect(projects[0].name).toEqual('chromium')
255+
expect(projects[0].config.include).toEqual([
256+
'test/**.test.ts',
257+
'**/*.global.test.{js,ts}',
258+
'**/*.shared.test.{js,ts}',
259+
])
260+
expect(projects[0].config.exclude).toEqual([
261+
'**/*.skip.test.{js,ts}',
262+
])
263+
expect(projects[0].config.includeSource).toEqual([
264+
'src/**/*.{js,ts}',
265+
])
266+
267+
// Firefox should only have its specific include/exclude/includeSource pattern (not parent patterns)
268+
expect(projects[1].name).toEqual('firefox')
269+
expect(projects[1].config.include).toEqual([
270+
'test/firefox-specific.test.ts',
271+
])
272+
expect(projects[1].config.exclude).toEqual([
273+
'test/webkit-only.test.ts',
274+
'test/webkit-extra.test.ts',
275+
])
276+
expect(projects[1].config.includeSource).toEqual([
277+
'src/firefox-compat.ts',
278+
])
279+
280+
// Webkit should only have its specific include/exclude/includeSource patterns (not parent patterns)
281+
expect(projects[2].name).toEqual('webkit')
282+
expect(projects[2].config.include).toEqual([
283+
'test/webkit-only.test.ts',
284+
'test/webkit-extra.test.ts',
285+
])
286+
expect(projects[2].config.exclude).toEqual([
287+
'test/firefox-specific.test.ts',
288+
])
289+
expect(projects[2].config.includeSource).toEqual([
290+
'src/webkit-compat.ts',
291+
])
292+
})
293+
294+
test('browser instances with empty include array should get parent include patterns', async () => {
295+
const { projects } = await vitest({}, {
296+
include: ['**/*.test.{js,ts}'],
297+
browser: {
298+
enabled: true,
299+
headless: true,
300+
instances: [
301+
{ browser: 'chromium', include: [] },
302+
{ browser: 'firefox' },
303+
],
304+
},
305+
})
306+
307+
// Both instances should inherit parent include patterns when include is empty or not specified
308+
expect(projects[0].config.include).toEqual(['test/**.test.ts', '**/*.test.{js,ts}'])
309+
expect(projects[1].config.include).toEqual(['test/**.test.ts', '**/*.test.{js,ts}'])
310+
})
311+
237312
test('filter for the global browser project includes all browser instances', async () => {
238313
const { projects } = await vitest({ project: 'myproject' }, {
239314
projects: [

0 commit comments

Comments
 (0)