test: quote mocha globs so mocha expands them, not the shell#409
Merged
Conversation
`npm test` ran `mocha test/**/*.test.js` unquoted. POSIX sh has no globstar, so `**` degrades to `*` and the pattern means `test/*/*.test.js` - files exactly one directory deep. Nothing currently matches that (all 36 test files are top-level), so the shell passes the pattern through literally and mocha globs it correctly itself. It works by fallback, not by design. The trap: the first time anyone adds a nested test file, the shell glob starts matching that file alone, mocha receives only it, and every top-level test silently stops running - with CI still green. Demonstrated by adding a throwaway test/nested/tmp.test.js: unquoted, under sh: 1 passing quoted, under sh: 734 passing, 1 pending Quoting defers expansion to mocha, which supports `**` properly and matches zero or more directories. Same treatment for test:watch, which had the identical pattern. `lint` was already quoted. No change to the resolved file set: 733 passing, 1 pending before and after. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
npm testranmocha test/**/*.test.jsunquoted. POSIX sh has no globstar, so**degrades to*and the pattern meanstest/*/*.test.jsThe trap: the first time anyone adds a nested test file, the shell glob starts matching that file alone, mocha receives only it, and every top-level test silently stops running - with CI still green.
Demonstrated by adding a throwaway test/nested/tmp.test.js:
unquoted, under sh: 1 passing
quoted, under sh: 734 passing, 1 pending
Quoting defers expansion to mocha, which supports
**properly and matches zero or more directories. Same treatment for test:watch, which had the identical pattern.lintwas already quoted.No change to the resolved file set: 733 passing, 1 pending before and after.