
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
jest-resolve-no-esm
Advanced tools
A jest-resolve fork that optionally disables the self-described "bad version" of Jest's attempt at replicating Node's type resolution algorithm
A jest-resolve fork that optionally disables the self-described "bad version" of Jest's attempt at replicating Node's type resolution algorithm.
Jest's ESM support is too incomplete. Specifically:
There is no jest.requireActual function (e.g. a jest.importActual) for ES
modules. This makes using jest.unstable_mockModule
too annoying since, among other
difficulties,
I can't seem to import a module with the goal of modifying only a single of its exports while leaving the rest as they are.
With something like jest.spyOn and
babel-plugin-explicit-exports-references,
this becomes is trivial. Unfortunately...
There is no jest.spyOn support in ESM mode because, as far as current Jest
spying functionality is concerned,
ES modules are immutable.
So, the solution is to just transpile everything back to CJS so we can regain our mocking and spying abilities. This has been my solution for a long time and it's been working perfectly fine up until (relatively) recently, where Jest updated its resolution algorithm in an attempt to progress its ESM support.
An unfortunate side-effect of this is that, even when
transformIgnorePatterns: [] and transform: { ... } are configured in a Jest
config file for full CJS transpilation, jest-resolve will still attempt to load
the now-transpiled-CJS-module as if it were ESM just because its file names end
in .js and the nearest package.json file contains "type": "module".
This fork allows me to disable ESM loading when
process.env.JEST_RESOLVE_NO_ESM is truthy, which avoids false positive
"errors" like Must use import to load ES Module: ....
[!NOTE]
For now,
.mjsand.mtsfiles will always be loaded as ESM even when using this module. This may be revisited later or, ideally, one day this entire package and other annoying workarounds will be obsoleted because Jest will support modern Node's ability torequireES modules natively.
npm install --save-dev jest-resolve@npm:jest-resolve-no-esm@30 jest
[!NOTE]
You may need to use the
package.jsonoverrides feature for a complete installation. See this package for an example.
JEST_RESOLVE_NO_ESM=true npx jest
Alternatively, you could set process.env.JEST_RESOLVE_NO_ESM = 'true' in a
Jest config file or
setup file.
For example, unified-utils uses this package to test its ESM-only packages.
FAQs
A jest-resolve fork that optionally disables the self-described "bad version" of Jest's attempt at replicating Node's type resolution algorithm
The npm package jest-resolve-no-esm receives a total of 0 weekly downloads. As such, jest-resolve-no-esm popularity was classified as not popular.
We found that jest-resolve-no-esm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.