Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9423dc0

Browse filesBrowse files
authored
fix: --project negation excludes browser instances (#10131)
1 parent b865b4d commit 9423dc0
Copy full SHA for 9423dc0

3 files changed

+78-3Lines changed: 78 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/vitest/src/node/core.ts‎

Copy file name to clipboardExpand all lines: packages/vitest/src/node/core.ts
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,21 @@ export class Vitest {
16431643
return regexp.test(name)
16441644
})
16451645
}
1646+
1647+
/** @internal */
1648+
isExcludedByProjectFilter(name: string): boolean {
1649+
const projects = this._config?.project || this._cliOptions?.project
1650+
if (!projects || !projects.length) {
1651+
return false
1652+
}
1653+
return toArray(projects).some((project) => {
1654+
if (!project.startsWith('!')) {
1655+
return false
1656+
}
1657+
const positivePattern = project.slice(1)
1658+
return wildcardPatternToRegExp(positivePattern).test(name)
1659+
})
1660+
}
16461661
}
16471662

16481663
function assert(condition: unknown, property: string, name: string = property): asserts condition {
Collapse file

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

Copy file name to clipboardExpand all lines: packages/vitest/src/node/projects/resolveProjects.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ export async function resolveBrowserProjects(
211211
if (!project.config.browser.enabled) {
212212
return
213213
}
214+
const originalName = project.config.name
214215
const instances = project.config.browser.instances || []
215-
if (instances.length === 0) {
216+
if (instances.length === 0 || vitest.isExcludedByProjectFilter(originalName)) {
216217
removeProjects.add(project)
217218
return
218219
}
219-
const originalName = project.config.name
220-
// if original name is in the --project=name filter, keep all instances
220+
// if original name matches a positive filter, keep all instances
221+
// otherwise, filter instances individually (user may target a specific instance name)
221222
const filteredInstances = vitest.matchesProjectFilter(originalName)
222223
? instances
223224
: instances.filter((instance) => {
Collapse file

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

Copy file name to clipboardExpand all lines: test/cli/test/config/browser-configs.test.ts
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,65 @@ test('browser instances with empty include array should get parent include patte
317317
expect(projects[1].config.include).toEqual(['**/*.test.{js,ts}'])
318318
})
319319

320+
test('negation filter excludes all browser instances', async () => {
321+
const { projects } = await vitest({ project: '!myproject' }, {
322+
projects: [
323+
{
324+
test: {
325+
name: 'myproject',
326+
browser: {
327+
enabled: true,
328+
provider: playwright(),
329+
headless: true,
330+
instances: [
331+
{ browser: 'chromium' },
332+
{ browser: 'firefox' },
333+
{ browser: 'webkit' },
334+
],
335+
},
336+
},
337+
},
338+
{
339+
test: {
340+
name: 'other',
341+
},
342+
},
343+
],
344+
})
345+
expect(projects.map(p => p.name)).toEqual([
346+
'other',
347+
])
348+
})
349+
350+
test('negation wildcard filter excludes all matching browser instances', async () => {
351+
const { projects } = await vitest({ project: '!my*' }, {
352+
projects: [
353+
{
354+
test: {
355+
name: 'myproject',
356+
browser: {
357+
enabled: true,
358+
provider: playwright(),
359+
headless: true,
360+
instances: [
361+
{ browser: 'chromium' },
362+
{ browser: 'firefox' },
363+
],
364+
},
365+
},
366+
},
367+
{
368+
test: {
369+
name: 'other',
370+
},
371+
},
372+
],
373+
})
374+
expect(projects.map(p => p.name)).toEqual([
375+
'other',
376+
])
377+
})
378+
320379
test('filter for the global browser project includes all browser instances', async () => {
321380
const { projects } = await vitest({ project: 'myproject' }, {
322381
projects: [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.