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

[Bug]: v30-alpha.5 TestPathPatterns pattern-match regression #15109

Closed
connectdotz opened this issue Jun 7, 2024 · 6 comments · Fixed by #15235
Closed

[Bug]: v30-alpha.5 TestPathPatterns pattern-match regression #15109

connectdotz opened this issue Jun 7, 2024 · 6 comments · Fixed by #15235

Comments

@connectdotz
Copy link
Contributor

connectdotz commented Jun 7, 2024

Version

30.0.0-alpha.5

Steps to reproduce

This can be demonstrated with jest's own examples/getting-started on a Window vscode powershell terminal:

  1. clone https://github.com/jestjs/jest
  2. copy the examples/getting-started to a new folder outside of Jest, so we can change the jest version freely.
  3. goto this standalone getting-started folder
  4. edit package.json to change the jest and babel-jest versions to 30.0.0-alpha.5
  5. yarn install
  6. run a specific test like this in a powershell terminal:
> yarn jest --testLocationInResults --testNamePattern "adds 1 \+ 2 to equal 3$" --no-coverage --colors --watchAll=false --testPathPatterns "c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js"

Expected behavior

Expect this to work just like with jest 29.x.

Edit package.json to update jest and babel-jest to 29.7.0; run yarn install then run the command again (replacing --TestPathPatterns with --TestPathPattern):

PS C:\Users\dev\github\open-source\getting-started> yarn jest --testLocationInResults --testNamePattern "adds 1 \+ 2 to equal 3$" --no-coverage --colors --watchAll=false --testPathPattern "c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js"
js";dbee3b2e-0ab6-4105-a99f-3a96e3b4cf5eyarn run v1.22.19                                             i
$ C:\Users\dev\github\open-source\getting-started\node_modules\.bin\jest --testLocationInResults --testNamePattern "adds 1 \+ 2 to equal 3$" --no-coverage --colors --watchAll=false --testPathPattern c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js
 PASS  ./sum.test.js
  √ adds 1 + 2 to equal 3 (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.669 s, estimated 1 s
Ran all test suites matching /c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js/i with tests matching "adds 1 \+ 2 to equal 3$".
Done in 1.23s.

Actual behavior

the pattern match failed so no test is run:

PS C:\Users\dev\github\open-source\getting-started> yarn jest --testLocationInResults --testNamePattern "adds 1 \+ 2 to equal 3$" --no-coverage --colors --watchAll=false --testPathPatterns "c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js"
yarn run v1.22.19
$ C:\Users\dev\github\open-source\getting-started\node_modules\.bin\jest --testLocationInResults --testNamePattern "adds 1 \+ 2 to equal 3$" --no-coverage --colors --watchAll=false --testPathPatterns c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\Users\dev\github\open-source\getting-started
  4 files checked.
  testMatch: **/__tests__/**/*.?([mc])[jt]s?(x), **/?(*.)+(spec|test).?([mc])[jt]s?(x) - 1 match      
  testPathIgnorePatterns: \\node_modules\\ - 4 matches
  testRegex:  - 0 matches
Pattern: c:\\Users\\dev\\github\\open-source\\getting-started\\sum\.test\.js - 0 matches
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Additional context

  • This issue only occurs on Windows. It works as expected on macOS, as far as I can tell.
  • Also noticed jest seems to perform a case-insensitive match for TestPathPattern in v29.x. Can't tell if v30 is doing the same.

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^30.0.0-alpha.5 => 30.0.0-alpha.5
@connectdotz
Copy link
Contributor Author

@SimenB any insight on this issue?

@connectdotz
Copy link
Contributor Author

@SimenB, sorry to ping you again. This issue has blocked the release of our jest@30 support PR (jest-community/vscode-jest#1153). Has the path-regex-matching algorithm changed intentionally? The same path pattern is recognized in v29 but not in v30. If this is a breaking change in v30 and not a bug, please let us know the right path forward so we can fix the PR and start to support jest@30 users.

Copy link

github-actions bot commented Aug 1, 2024

This issue is stale because it has been open 30 days 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 Aug 1, 2024
@connectdotz
Copy link
Contributor Author

I've been investigating this issue further and it looks like the problem might be related to TestPathPatterns.regexString(), specifically in how it prefixes rootDirRegex.

It seems that the current implementation only considers POSIX-style path patterns and might be missing Windows absolute path patterns, like c:\\dir\\test-file\.test\.ts, which were supported in earlier Jest versions.

This looks like a bug to me, cc @SimenB and @brandonchinn178 for insights and actions.

@brandonchinn178
Copy link
Contributor

brandonchinn178 commented Aug 3, 2024

It looks like the issue is line 79, right? It assumes an absolute path starts with a slash, but that's not true in Windows.

Does look like a bug. Not sure what the correct fix is, I don't work with Windows paths too much. Should it also check for starting with \w:\\?

Trying a quick fix here: #15235

Copy link

github-actions bot commented Sep 8, 2024

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 Sep 8, 2024
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.

2 participants