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

testFileDir always matches #4425

Closed
6 tasks done
timbrinded opened this issue Nov 2, 2023 · 6 comments · Fixed by #4538
Closed
6 tasks done

testFileDir always matches #4425

timbrinded opened this issue Nov 2, 2023 · 6 comments · Fixed by #4538
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@timbrinded
Copy link

timbrinded commented Nov 2, 2023

Describe the bug

Given the tree:

.
├── tests1
│   └── test.spec.ts
├── tests11
│   └── test.spec.ts
└── tests2
    └── test.spec.ts

Vitest will match tests1 & tests11 when supplied with filter tests1/.

Whilst i recognise that you can use the include option or even specifying direct filenames, that is a very heavyhanded and hardcoded approach which doesn't fit large test repositories (in my case i have 400+ test files in nested directories).

Instead it would be less-surprising for it to match based on inputs such as tests1/ to only use that directory. A regex \b would also be acceptable.

Reproduction

Using this StackBlitz you can execute the following scripts that illustrates a plausible scenario:

  • pnpm test:all : ✅
  • pnpm test:1 : ❌ - Runs tests for both folder1 and folder11
  • pnpm test:2 : ✅
  • pnpm test:11 : ✅

Important

In reality, most scenarios wouldn't be matching based on numbers, but i've got into weird scenarios where expressions collide with each other: test_blocks and test_blockscope

System Info

all

Used Package Manager

pnpm

Validations

Copy link

stackblitz bot commented Nov 2, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sheremet-va
Copy link
Member

sheremet-va commented Nov 2, 2023

Yes, the filter is just string.includes(), this is expected. You need to provide / yourself

@timbrinded
Copy link
Author

if you see the repro, the filter contains the / but it is being ignored

@timbrinded
Copy link
Author

@sheremet-va did you see the comment above? The defect appears valid to me.

@sheremet-va
Copy link
Member

sheremet-va commented Nov 14, 2023

You are correct, this is a bug. It probably happens because of this check (relative removes all / at the end):

return testFile.includes(f) || testFile.includes(relative(dir, f))

To fix this, we should append / if it was there before relative was called.

@sheremet-va sheremet-va added bug pr welcome p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Nov 14, 2023
@ibuibu
Copy link
Contributor

ibuibu commented Nov 19, 2023

I challenge to contribute.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants