-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
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:
- Clone https://github.com/ecraig12345/repro-jest-util-dep (or make a similar repo with either current
yarn
+nodeLinker: pnpm
setting, orpnpm
) - Verify
yarn -v
shows 4.1.1 yarn
yarn jest
=> observe that tests run but there's an "Invalid testPattern" message as shown belowyarn 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).
jest/packages/jest-config/src/normalize.ts
Lines 412 to 421 in 1d682f2
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