Skip to content

fix(config): allow --config when cwd has no discoverable config (fixes #16457) - #16520

Open
saiyam-jain-dev wants to merge 2 commits into
jestjs:mainfrom
saiyam-jain-dev:fix-config-flag-cwd-resolve
Open

saiyam-jain-dev wants to merge 2 commits into
jestjs:mainfrom
saiyam-jain-dev:fix-config-flag-cwd-resolve

Conversation

@saiyam-jain-dev

Copy link
Copy Markdown

Summary

Fixes #16457

When --config \ was passed from a working directory that does not contain a \package.json\ or discoverable Jest config file, Jest failed with:
\
Error: Could not find a config file based on provided values:
path: "..."
cwd: "..."
\
This was a regression introduced in #16411 in \packages/jest-config/src/index.ts. While evaluating \suppliesGlobalConfig,
esolveConfigPath(root, cwd, projectIsCwd)\ was unconditionally invoked on
oot\ (\cwd) even when !skipArgvConfigOption\ was true (meaning the project config was already supplied by \�rgv.config).

This PR:

  • Short-circuits \suppliesGlobalConfig\ when !skipArgvConfigOption\ is true.
  • Safely wraps the
    esolveConfigPath\ check in a \ ry / catch\ so unexpected resolution failures during global config supply checks do not throw unhandled exceptions.
  • Updates \CHANGELOG.md.
  • Adds an e2e regression test in \e2e/tests/config.test.ts.

Test plan

  • Added automated test in \e2e/tests/config.test.ts\ verifying --config \ runs successfully when \cwd\ has no config file.

@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 00d4035
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6af23a2bfa53813fc0803c4c
😎 Deploy Preview https://deploy-preview-16520--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label Oct 26, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16520

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16520

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16520

create-jest

npm i https://pkg.pr.new/create-jest@16520

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16520

expect

npm i https://pkg.pr.new/expect@16520

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16520

jest

npm i https://pkg.pr.new/jest@16520

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16520

jest-circus

npm i https://pkg.pr.new/jest-circus@16520

jest-cli

npm i https://pkg.pr.new/jest-cli@16520

jest-config

npm i https://pkg.pr.new/jest-config@16520

@jest/console

npm i https://pkg.pr.new/@jest/console@16520

@jest/core

npm i https://pkg.pr.new/@jest/core@16520

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16520

jest-diff

npm i https://pkg.pr.new/jest-diff@16520

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16520

jest-each

npm i https://pkg.pr.new/jest-each@16520

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16520

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16520

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16520

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16520

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16520

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16520

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16520

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16520

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16520

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16520

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16520

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16520

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16520

jest-mock

npm i https://pkg.pr.new/jest-mock@16520

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16520

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16520

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16520

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16520

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16520

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16520

jest-runner

npm i https://pkg.pr.new/jest-runner@16520

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16520

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16520

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16520

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16520

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16520

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16520

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16520

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16520

@jest/types

npm i https://pkg.pr.new/@jest/types@16520

jest-util

npm i https://pkg.pr.new/jest-util@16520

jest-validate

npm i https://pkg.pr.new/jest-validate@16520

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16520

jest-worker

npm i https://pkg.pr.new/jest-worker@16520

pretty-format

npm i https://pkg.pr.new/pretty-format@16520

commit: 00d4035

@saiyam-jain-dev
saiyam-jain-dev force-pushed the fix-config-flag-cwd-resolve branch from 72fbde6 to 00d4035 Compare November 9, 2026 21:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --config <file> fails with "Could not find a config file" when the cwd has no discoverable config (jest-config >= 30.5.1)

1 participant