Repository navigation
fix(jest-config): honor explicit --config path when cwd has no discoverable config - #16458
Dextheking1 wants to merge 6 commits into
Conversation
…erable config readConfigs computed suppliesGlobalConfig by calling resolveConfigPath on the project root, which throws 'Could not find a config file' when the cwd has no discoverable config - even when an explicit --config <file> was passed and already resolved successfully. Guard the discovery call: a project root with no discoverable config simply does not supply the global config through discovery. Fixes jestjs#16457
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
…atforms The new regression test for jestjs#16457 failed CI in three ways, all in the test itself (the fix is unaffected): - Static Checks: `jest.SpyInstance` is not exported by @jest/globals 30; annotate the spy as `jest.SpiedFunction<() => string>`. - macOS: `os.tmpdir()` (/var/...) differs from the realpath jest reports (/private/var/...); create the fixture dir through `fs.realpathSync` so assertions compare canonical paths. - Windows: the mocked cwd contained an 8.3 short-name segment, so jest's internal `tryRealpath(process.cwd())` no longer matched the project path and the test fell into the config-discovery path. Mocking with the canonical path keeps `projectIsCwd` true.
Follow-up to the cross-platform stabilization:
- `import * as fs from 'fs'` is banned by `no-restricted-imports`; use
`graceful-fs` like the other jest-config tests.
- sort-keys: `{force: true, recursive: true}` in the `rmSync` cleanup.
…test `fs.realpathSync` does not expand Windows 8.3 short names while jest's internal `tryRealpath` (realpathSync.native) does, so the mocked cwd still mismatched on Windows. Use the same `tryRealpath` from jest-util that the source uses, making the canonicalization identical.
Wrap the tryRealpath(mkdtempSync(...)) call to satisfy prettier line length in the Static Checks job.
|
The "Node LTS on Ubuntu with leak detection" failure is unrelated to this PR: the failing suite is |
|
The leak-detection job failed on packages/jest-mock whenCalledWith.test.ts, which this PR does not touch (the change is in jest-config). The leak detector is experimental and this reads as a flake. Could a maintainer re-run that job? |
Fixes #16457
Summary
jest --config <file>failed withCould not find a config file based on provided valueswhen run from a directory (and ancestors) containing no discoverable config, even though the explicitly passed config file resolved fine.Root cause
Regression from #16411. In
readConfigs(packages/jest-config/src/index.ts), thesuppliesGlobalConfigcheck callsresolveConfigPath(root, cwd, projectIsCwd)on the project root to compare it against the already-resolvedconfigPath. When the project root has no discoverable config,resolveConfigPaththrows instead of simply not matching, so the whole run dies before the per-projectreadConfig-- which would have honored the explicit--config-- ever runs.Fix
Guard the discovery call with try/catch: if no config can be discovered for the project root, it simply does not supply the global config through discovery. No behavior change when a config is discoverable.
Testing
packages/jest-config/src/__tests__/readConfigsExplicitConfig.test.ts: callsreadConfigswith an explicit--configfile from a cwd with no discoverable config (mockedprocess.cwd()into a fresh temp dir, mirroring the issue'smktemp -drepro). Fails on the base commit with the exactCould not find a config fileerror from the issue; passes with the fix.readConfigs,readConfig,readInitialOptions,resolveConfigPathall pass (62/62).