Skip to content

test: quote mocha globs so mocha expands them, not the shell#409

Merged
TimelordUK merged 1 commit into
masterfrom
fix/quote-test-globs
Jul 19, 2026
Merged

test: quote mocha globs so mocha expands them, not the shell#409
TimelordUK merged 1 commit into
masterfrom
fix/quote-test-globs

Conversation

@TimelordUK

Copy link
Copy Markdown
Owner

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.

`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]>
@TimelordUK
TimelordUK merged commit 7652a3f into master Jul 19, 2026
8 of 10 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