fix: make npm test run on Windows (node <21)#118
Open
Lakshya77089 wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
npm testfails on Windows. The root and pi-extension test scripts pass a glob to the node test runner:POSIX shells (so CI, on ubuntu) expand the glob before node sees it, but
cmd.exedoes not, and node < 21 does not glob--testpaths natively. So on Windows the runner gets a literaltests/*.test.jsand exits withCould 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:
node --test tests/(directory)node --test tests/**/*.test.js(native glob)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.jsis the alternative — happy to switch to that instead.