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

filter should exclude cwd #3344

Closed
6 tasks done
benmccann opened this issue May 10, 2023 · 4 comments · Fixed by #3353
Closed
6 tasks done

filter should exclude cwd #3344

benmccann opened this issue May 10, 2023 · 4 comments · Fixed by #3353
Labels
enhancement New feature or request pr welcome

Comments

@benmccann
Copy link
Contributor

Describe the bug

I did cd ~/src and then did a git clone of a Vitest project which has the command vitest --run src. Because my project was held in a directory named src, the src filter matched all files rendering it useless. The filter should work the same regardless of where the user checks out the project because we don't know what the user's directory structure might be and we would otherwise have to list all directory names that they should avoid putting the project into

Reproduction

mkdir src
cd src
git clone git@github.com:sveltejs/kit.git
cd kit/packages/kit
pnpm install

Now edit package.json and change "test:unit": "vitest run", to "test:unit": "vitest run src", and do rm vitest.config.js. When you run test:unit all tests should pass, but it will end up running some that live in the test directory because the src directory is ignored, so some will fail

System Info

System:
    OS: Linux 5.19 Ubuntu 22.10 22.10 (Kinetic Kudu)
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 113.0.5672.92
  npmPackages:
    vite: ^4.3.0 => 4.3.0

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented May 10, 2023

The filter is just filename.includes(filter). If you have a file named something-src-something outside of src directory it will still run it.

I recommend just adding a slash to it.

@sheremet-va
Copy link
Member

If you want to specify a directory to run, you can use --dir option.

@benmccann
Copy link
Contributor Author

A slash doesn't help because it still matches. The --dir option does work.

It still seems weird to me that what directory the project is held in should affect whether or not a filter matches as it makes filters behave differently on each user's machine. Without knowing the implementation, there's also a chance it might be more performant to build the filenames as relative to the cwd rather than absolute because when you search against them you'll be searching shorter strings (and they'll also take less memory and run GC less though that difference might be too small to matter).

@AriPerkkio
Copy link
Member

Just to get this right - this issue is about the test name filter being matched against whole path including the current working directory? It should only match against relative path from current working directory.

Small demo:

/x/y/vitest-example-project
├── package.json
├── src
├── tests
|  ├── animals.test.ts
|  ├── example.test.ts
|  └── math.test.ts
└── vitest.config.ts
# Runs only test/math.test.ts
$ pnpm run test math

# Runs all tests due to cwd path "/x/y/vitest-example-project"
# Instead should run only test/example.test.ts
$ pnpm run test example

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants