Skip to content

fix: make npm test run on Windows (node <21)#118

Open
Lakshya77089 wants to merge 2 commits into
DietrichGebert:mainfrom
Lakshya77089:fix-windows-test-glob
Open

fix: make npm test run on Windows (node <21)#118
Lakshya77089 wants to merge 2 commits into
DietrichGebert:mainfrom
Lakshya77089:fix-windows-test-glob

Conversation

@Lakshya77089

@Lakshya77089 Lakshya77089 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

npm test fails on Windows. The root and pi-extension test scripts pass a glob to the node test runner:

node --test tests/*.test.js
node --test ./test/*.test.js

POSIX shells (so CI, on ubuntu) expand the glob before node sees it, but cmd.exe does not, and node < 21 does not glob --test paths natively. So on Windows the runner gets a literal tests/*.test.js and exits with Could not find 'tests/*.test.js'.

Found while testing #79 on Windows (node 20.20.0).

Fix: explicit file list

No single auto-discovery form works across node versions:

form node 20 node 22 (CI)
node --test tests/ (directory) ❌ treats path as a module → MODULE_NOT_FOUND
node --test tests/**/*.test.js (native glob) ❌ no glob support pre-21
explicit file list

So the scripts now list the test files explicitly — runs identically on node 18/20/22, every OS, no shell glob.

Verified

npm test → exit 0: 51 root tests + 11 pi-extension tests. Confirmed the listed files exactly match what's on disk in both dirs.

Tradeoff

Explicit lists don't auto-discover, so a newly added test file must be added to the script or it silently won't run. If you'd rather keep auto-discovery and require node ≥ 21 (CI is already on 22), the native-glob form node --test tests/**/*.test.js is the alternative — happy to switch to that instead.

The test scripts pass a 'tests/*.test.js' / './test/*.test.js' glob to
node --test. POSIX shells expand it, but cmd.exe does not and node <21
does not glob --test paths natively, so npm test fails for every Windows
contributor with 'Could not find ...'. Pass the directory instead; node
discovers the *.test.js files itself. Same files run (verified), now
cross-platform.
The directory form (node --test tests/) runs on node 20 but fails on
node 22 — which is what CI uses — because node >=22 treats the path as a
module to load, not a search root (MODULE_NOT_FOUND). The node-native
glob form fails the other way, on node <21. No single auto-discovery
form works across both, so list the files explicitly: runs identically
on node 18/20/22, every OS, no shell glob. Verified npm test green
locally (node 20) and matches CI's node 22.
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