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]: jest-util is missing a dependency on jest-regex-util (and error is misleading) #14990

Closed
ecraig12345 opened this issue Mar 27, 2024 · 4 comments · Fixed by #15030
Closed
Labels

Comments

@ecraig12345
Copy link

ecraig12345 commented Mar 27, 2024

Version

30.0.0-alpha.3 (doesn't repro in 29)

Steps to reproduce

You can see the missing dependency by looking at the code: jest-util uses jest-regex-util as shown below, but it's not listed in jest-util/package.json.

import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';

That code will work when using a package manager/linker that uses a hoisted node_modules layout, but it will fail to find the implicit dependency with a strict/non-hoisted installation layout, such as yarn v3/4 with nodeLinker: pnpm, pnpm itself, or probably Yarn PnP.

Repro steps to see the misleading error message caused by this issue + non-hoisted installation:

  1. Clone https://github.com/ecraig12345/repro-jest-util-dep (or make a similar repo with either current yarn+nodeLinker: pnpm setting, or pnpm)
  2. Verify yarn -v shows 4.1.1
  3. yarn
  4. yarn jest => observe that tests run but there's an "Invalid testPattern" message as shown below
  5. yarn jest other => observe that all tests run, not only the selected test

Expected behavior

The tests pass with no odd error messages.

Actual behavior

  • Running all tests works, but there's a message Invalid testPattern supplied. Running all tests instead.
  • Trying to filter tests still runs all tests, with the same error message.
$ yarn jest
  Invalid testPattern  supplied. Running all tests instead.
  Invalid testPattern  supplied. Running all tests instead.
 PASS  ./other.test.js
 PASS  ./index.test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.346 s, estimated 1 s
Ran all test suites.

$ yarn jest other
  Invalid testPattern other supplied. Running all tests instead.
  Invalid testPattern other supplied. Running all tests instead.
 PASS  ./other.test.js
 PASS  ./index.test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.27 s, estimated 1 s
Ran all test suites.

Additional context

Debugging into the code shows that the Invalid testPattern log comes from this code block in jest-config, which catches the error (in this case a module not found error) and assumes it's an invalid pattern. The root issue is the missing dependency, but the error handling here could be improved too (not assuming all errors are invalid patterns).

try {
testPathPatterns.validate();
} catch {
clearLine(process.stdout);
// eslint-disable-next-line no-console
console.log(
chalk.red(
` Invalid testPattern ${testPathPatterns.toPretty()} supplied. ` +
'Running all tests instead.',

Environment

System:
    OS: macOS 12.7.4
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 4.1.1 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
  npmPackages:
    jest: ^30.0.0-alpha.2 => 30.0.0-alpha.3
@mrazauskas
Copy link
Contributor

Just open a PR adding jest-regex-util as a dependency to jest/packages/jest-util/package.json. It is obviously missing. Got overlook in #12519, this is what happens naturally with large PRs.

@SimenB
Copy link
Member

SimenB commented Mar 27, 2024

Yeah, happy to take a PR adding the missing dep 👍 Would you be able to do that @ecraig12345?

@SimenB
Copy link
Member

SimenB commented May 12, 2024

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 Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants