chore: migrate CoverageReporter test off mock-fs - #16401
Conversation
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.
✅ Deploy Preview for jestjs ready!
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: |
There was a problem hiding this comment.
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-fsusage inCoverageReporter.test.jswith real fixture files and cwd-relative/glob threshold paths. - Removed
mock-fsfrom root andjest-reportersdependencies and pruned it fromyarn.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.
The coverage-threshold fixtures are intentionally empty; only their paths matter. Other packages' empty fixtures are already listed here.
|
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: |
|
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. |
Summary
mock-fs throws at
requiretime on Node 26.8+:nodejs/node#65327 (in 26.8.0) made
fs.readFiledo open+fstat+read+close in one thread pool round trip, sobinding.openis never called and mock-fs'sReadFileContextprototype sniffing comes backundefined. 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.jswas our only use of mock-fs, and it only needed a tree of empty files on disk forglob.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 frompath.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-fse2e fixture is unaffected — despite the name it only mocksfs.writeFileSyncwithjest.fn().Test plan
15/15 in
CoverageReporter.test.json Node 26.7.0 and 26.8.1, from both the repo root and the package directory as cwd.yarn constraintsandyarn dedupe --checkpass after the dependency removal.