Skip to content

chore: migrate CoverageReporter test off mock-fs - #16401

Merged
SimenB merged 2 commits into
jestjs:mainfrom
SimenB:remove-mock-fs
Aug 27, 2026
Merged

SimenB merged 2 commits into
jestjs:mainfrom
SimenB:remove-mock-fs

Conversation

@SimenB

@SimenB SimenB commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

mock-fs throws at require time on Node 26.8+:

TypeError: Cannot read properties of undefined (reading 'read')
    at exports.patchReadFileContext (mock-fs/lib/readfilecontext.js:40:30)

nodejs/node#65327 (in 26.8.0) made fs.readFile do open+fstat+read+close in one thread pool round trip, so binding.open is never called and mock-fs's ReadFileContext prototype sniffing comes back undefined. Reported upstream as tschaub/mock-fs#447, but the interception approach is broken more deeply than the sniff (reads that take the new one-shot path bypass the mocked binding entirely), so a fix is not around the corner.

CoverageReporter.test.js was our only use of mock-fs, and it only needed a tree of empty files on disk for glob.sync-based coverage-threshold matching. Replace it with a checked-in tree of empty fixture files under __tests__/__fixtures__/; the test builds its relative and glob threshold paths from path.relative(process.cwd(), fixtureDir), so it keeps exercising relative-path and glob threshold resolution against the real filesystem without mocks or cwd games, and works from any cwd. Drop the dependency.

The snapshot-mock-fs e2e fixture is unaffected — despite the name it only mocks fs.writeFileSync with jest.fn().

Test plan

yarn jest packages/jest-reporters

15/15 in CoverageReporter.test.js on Node 26.7.0 and 26.8.1, from both the repo root and the package directory as cwd. yarn constraints and yarn dedupe --check pass after the dependency removal.

mock-fs throws at require time on Node 26.8+ (nodejs/node#65327 made
fs.readFile bypass binding.open, breaking its ReadFileContext sniffing;
tschaub/mock-fs#447). The test only needed empty files on disk for glob
threshold matching, so resolve the relative and glob thresholds against
a checked-in fixture tree instead and drop the dependency.
@SimenB
SimenB requested a lite review from Copilot August 27, 2026 13:26
@netlify

netlify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for jestjs ready!

Name Link
🔨 Latest commit f9fac09
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a90413202dce1000889eeca
😎 Deploy Preview https://deploy-preview-16401--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 Aug 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: f9fac09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the mock-fs dependency (which fails on Node 26.8+) by migrating the CoverageReporter unit test to use a checked-in on-disk fixture tree under packages/jest-reporters/src/__tests__/__fixtures__/, while still exercising relative/glob-based coverageThreshold resolution against the real filesystem.

Changes:

  • Replaced mock-fs usage in CoverageReporter.test.js with real fixture files and cwd-relative/glob threshold paths.
  • Removed mock-fs from root and jest-reporters dependencies and pruned it from yarn.lock.
  • Added a fixture directory structure for coverage-threshold path and glob matching scenarios.

Reviewed changes

Copilot reviewed 3 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package.json Removes mock-fs dependency from the root workspace.
packages/jest-reporters/package.json Removes mock-fs from jest-reporters dependencies.
yarn.lock Removes the mock-fs@^5.5.0 entry and references.
packages/jest-reporters/src/__tests__/CoverageReporter.test.js Updates the test to use checked-in fixtures via cwd-relative paths and globs rather than mock-fs.
packages/jest-reporters/src/__tests__/__fixtures__/path-test/100pc_coverage_file.js Adds on-disk fixture for threshold path resolution tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/000pc_coverage_file.js Adds on-disk fixture for glob/dir matching tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/050pc_coverage_file.js Adds on-disk fixture for glob/dir matching tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/100pc_coverage_file.js Adds on-disk fixture for glob/dir matching tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/full_path_file.js Adds on-disk fixture for absolute-path threshold tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/non_covered_file.js Adds on-disk fixture for non-covered threshold handling tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/relative_path_file.js Adds on-disk fixture for relative-path threshold tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file1.js Adds on-disk fixture for glob threshold tests.
packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file2.js Adds on-disk fixture for glob threshold tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/jest-reporters/src/__tests__/CoverageReporter.test.js
Comment thread packages/jest-reporters/src/__tests__/CoverageReporter.test.js
The coverage-threshold fixtures are intentionally empty; only their
paths matter. Other packages' empty fixtures are already listed here.
@SimenB
SimenB merged commit 3aa9b8b into jestjs:main Aug 27, 2026
104 of 105 checks passed
@SimenB
SimenB deleted the remove-mock-fs branch August 27, 2026 14:16
@BadIdeaException

Copy link
Copy Markdown

If you're interested, I reimplemented mock-fs on memfs a while ago when it became clear that its core approach would be untenable medium term:

https://github.com/BadIdeaException/mock-fs-reborn

@github-actions

Copy link
Copy Markdown

This pull request 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 Sep 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants