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

Passing in test files to CLI should be matched against relative path #10746

Closed
brandon-leapyear opened this issue Oct 31, 2020 · 9 comments · Fixed by #12519
Closed

Passing in test files to CLI should be matched against relative path #10746

brandon-leapyear opened this issue Oct 31, 2020 · 9 comments · Fixed by #12519

Comments

@brandon-leapyear
Copy link
Contributor

🚀 Feature Proposal

When running jest foo, foo should be matched against the path relative to package.json instead of its absolute path.

Motivation

We have a test file user.spec.ts, and accidentally running jest user runs all tests, because the full path of all the test files starts with /Users/my-username/.... It's also odd to run jest foo and not see the string "foo" anywhere in the output

$ jest test /Users

RUNS src/index.spec.ts
RUNS src/author.spec.ts
RUNS src/book.spec.ts

Example

Pitch

This oddity is confusing behavior that should at least be documented. The current documentation says

When you run jest with an argument, that argument is treated as a regular expression to match against files in your project.

which is confusing if the regular expression can also match directories outside of my project. I can't think of a good reason to keep this behavior (why would you want a regex matching all of the test files in your project?)

@brandon-leapyear
Copy link
Contributor Author

@jeysal
Copy link
Contributor

jeysal commented Oct 31, 2020

To be fair, Jest at least consistently does this (resolving to absolute paths) pretty much anywhere we use paths.
I regularly use it to match only a test.js I've created in the root by including the project directory name (jest my-project/test.js) however this could also be achieved in relative path matching.
I would say #7185 is the place to do such a change if we want if that ever happens - if we switch all paths to glob matching by default, those globs can also be relative to the cwd in CLI arguments, or root dir in config files.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@brandon-leapyear
Copy link
Contributor Author

I still think this would be good to fix

@github-actions github-actions bot removed the Stale label Feb 25, 2022
@SimenB
Copy link
Member

SimenB commented Feb 27, 2022

I'd honestly consider this a bug. We need to work if you pass an absolute path, but we should probably special case absolute paths instead. Matching on patterns outside of rootDir is just weird.

Is this something you'd be willing to work on?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 27, 2023
@brandonchinn178
Copy link
Contributor

PR is waiting for review

@SimenB
Copy link
Member

SimenB commented Oct 30, 2023

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants