Skip to content

test: make fs mocks tolerate non-string paths from the module loader#302

Merged
TimothyJones merged 2 commits into
masterfrom
fix/fs-mock-non-string-paths
Jul 18, 2026
Merged

test: make fs mocks tolerate non-string paths from the module loader#302
TimothyJones merged 2 commits into
masterfrom
fix/fs-mock-non-string-paths

Conversation

@TimothyJones

Copy link
Copy Markdown
Member

What

Guard the global fs.readFileSync / fs.lstatSync mocks in test/core.spec.js so non-string paths are delegated to the real fs instead of being fed to path.includes(...).

Why

CI has been red on ubuntu-latest since the vitest migration (#283) + the conventional-changelog deps modernization, with:

Error: Unable to load the "conventional-changelog-conventionalcommits" preset. Please make sure it's installed.
Caused by: TypeError: path.includes is not a function
  ❯ attemptingToReadPackageJson  test/core.spec.js:74
  ❯ (fs.readFileSync mock)       test/core.spec.js:126
  ❯ loadPreset                   conventional-changelog-preset-loader

The preset is installed. The four actualConventionalRecommendedBump tests run the real preset loader, whose dynamic import('conventional-changelog-conventionalcommits') reads the ESM module through fs with a non-string path (URL/Buffer/fd) on Linux. The mock assumed path was always a string, so path.includes(...) threw — and the preset loader rewrapped it as the misleading "make sure it's installed" message.

It passed locally because the CI matrix is ubuntu-latest + windows-latest only — no macOS, where the failure doesn't reproduce.

This is a test-harness bug, not a product regression — no shipped code changes, and the failure predates the 13.0.0 release.

Change

Non-string paths (module-loader reads) now pass straight to real fs; string paths keep the existing fixture handling. Test-only.

TimothyJones and others added 2 commits July 18, 2026 16:18
The global fs.readFileSync/lstatSync mocks in core.spec.js assumed `path`
was always a string and called `path.includes(...)` on it. The four
`actualConventionalRecommendedBump` tests exercise the real preset loader,
whose dynamic `import('conventional-changelog-conventionalcommits')` reads
the ESM module through fs with a non-string path (URL/Buffer/fd) on Linux.
That threw `TypeError: path.includes is not a function`, which the preset
loader rewrapped as the misleading "Unable to load the preset. Please make
sure it's installed." — failing CI on ubuntu while passing on macOS (which
is not in the CI matrix).

Delegate non-string paths straight to the real fs so module loading works;
string paths still get the fixture handling. Test-only change; no product
code is affected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
macOS was absent from the matrix, which is why the fs-mock preset-loading
failure went unnoticed locally (contributors on macOS) while CI on Linux
stayed red. Cover all three major platforms.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TimothyJones
TimothyJones merged commit ddb4ed4 into master Jul 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant