Skip to content

Commit 932d837

Browse files
authored
fix(watch): filename filter runs duplicate tests in workspaces (#8250)
1 parent 8a99880 commit 932d837

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/vitest/src/node/stdin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ export function registerConsoleShortcuts(
199199

200200
const filter = await watchFilter.filter(async (str: string) => {
201201
const files = await ctx.globTestFiles([str])
202-
return files.map(file => relative(ctx.config.root, file[1]))
202+
203+
return files
204+
.map(file => relative(ctx.config.root, file[1]))
205+
.filter((file, index, all) => all.indexOf(file) === index)
203206
})
204207

205208
on()

test/watch/test/stdin.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,41 @@ describe.each([true, false])('standalone mode is %s', (standalone) => {
3434
await vitest.waitForStdout('1 passed')
3535
})
3636

37+
test('filter by filename when multiple projects match same file', async () => {
38+
const { vitest } = await runVitest({
39+
...options,
40+
projects: [
41+
{
42+
test: {
43+
name: 'First',
44+
root: options.root,
45+
},
46+
},
47+
{
48+
test: {
49+
name: 'Second',
50+
root: options.root,
51+
},
52+
},
53+
],
54+
})
55+
56+
vitest.write('p')
57+
58+
await vitest.waitForStdout('Input filename pattern')
59+
60+
vitest.write('math')
61+
62+
await vitest.waitForStdout('Pattern matches 1 result')
63+
await vitest.waitForStdout('› math.test.ts')
64+
65+
vitest.write('\n')
66+
67+
// 2 due to count of projects
68+
await vitest.waitForStdout('2 passed')
69+
await vitest.waitForStdout('Filename pattern: math')
70+
})
71+
3772
test('filter by test name', async () => {
3873
const { vitest } = await runVitest(options)
3974

0 commit comments

Comments
 (0)