Skip to content
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
5 changes: 4 additions & 1 deletion packages/vitest/src/node/stdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export function registerConsoleShortcuts(

const filter = await watchFilter.filter(async (str: string) => {
const files = await ctx.globTestFiles([str])
return files.map(file => relative(ctx.config.root, file[1]))

return files
.map(file => relative(ctx.config.root, file[1]))
.filter((file, index, all) => all.indexOf(file) === index)
})

on()
Expand Down
35 changes: 35 additions & 0 deletions test/watch/test/stdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ describe.each([true, false])('standalone mode is %s', (standalone) => {
await vitest.waitForStdout('1 passed')
})

test('filter by filename when multiple projects match same file', async () => {
const { vitest } = await runVitest({
...options,
projects: [
{
test: {
name: 'First',
root: options.root,
},
},
{
test: {
name: 'Second',
root: options.root,
},
},
],
})

vitest.write('p')

await vitest.waitForStdout('Input filename pattern')

vitest.write('math')

await vitest.waitForStdout('Pattern matches 1 result')
await vitest.waitForStdout('› math.test.ts')
Comment on lines +62 to +63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failure before fix:


vitest.write('\n')

// 2 due to count of projects
await vitest.waitForStdout('2 passed')
await vitest.waitForStdout('Filename pattern: math')
})

test('filter by test name', async () => {
const { vitest } = await runVitest(options)

Expand Down
Loading