Skip to content

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

@brandon-leapyear

Description

@brandon-leapyear

🚀 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?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions