Repository navigation
fix: do not quote the test glob in the TypeScript template - #936
Open
Lalithkishore1224 wants to merge 1 commit into
Open
Lalithkishore1224 wants to merge 1 commit into
Lalithkishore1224 wants to merge 1 commit into
Conversation
The CommonJS TypeScript template generated a test script with a quoted
glob ("test/**/*.ts"). The quotes stop the shell from expanding it, so
node --test receives the pattern literally. Node.js 20 has no glob
support in the test runner and fails with "Could not find
'.../test/**/*.ts'". The JavaScript and ESM TypeScript templates already
pass the glob unquoted; this aligns the CommonJS TypeScript one with them.
Fixes fastify#756
Member
|
I'm relatively certain I added that to better support Windows |
There was a problem hiding this comment.
🟡 Changes recommended
Unquoted test/**/*.ts undergoes POSIX shell expansion that silently omits deeply nested tests, requiring recursive file enumeration and a shell-level regression test.
1 open issue
What changed in this PR
Addresses #756 by removing quotes around the test glob generated for CommonJS TypeScript projects, allowing shell expansion on Node.js versions without native test-runner glob support.
Changes:
- Aligns the CommonJS TypeScript test command with the other templates’ unquoted glob.
- Updates the expected script, adds an assertion against quoted globs, and adjusts the assertion count.
| File | Description |
|---|---|
test/generate-typescript.test.js |
Updates script assertions and the planned assertion count. |
generate.js |
Removes quotes around the CommonJS TypeScript test glob. |
Review effort: Balanced
| scripts: { | ||
| clean: 'node -e "require(\'fs\').rmSync(\'dist\', {recursive: true, force: true})"', | ||
| test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"', | ||
| test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register test/**/*.ts', |
This branch has not been deployed
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.

Fixes #756
The
testscript thatgenerate.jswrites forfastify generate --lang=ts(the CommonJS TypeScript template) wraps the glob in quotes:Because of the quotes the shell never expands the pattern, so
node --testgets the literal stringtest/**/*.ts. Glob support in the test runner only landed in Node.js 21, so on Node.js 20 (still in the CI matrix) and older the runner looks for a file with that exact name and fails withCould not find '.../test/**/*.ts', which is what the issue reports. On 22+ it happens to work because Node expands the pattern itself.The JavaScript templates and the ESM TypeScript template already pass the glob unquoted (
test/**/*.test.js,test/**/*.ts), so this just drops the quotes intypescriptTemplate.scripts.testto match them. With the shell expanding the pattern, the script works the same way on every Node version. A side effect is thattest/helper.tsis no longer handed to the runner as a test file on Node 22+ (it showed up as an extra "test" before).test/generate-typescript.test.jsnow expects the unquoted script and also asserts that the glob is not quoted.How I verified:
node --test test/generate-typescript.test.jsfails without the change togenerate.js(strictEqual on the script) and passes with it. Fullnpm testpasses (lint, template suites, 231 pass / 1 skipped in the CLI suite, tstyche).Generated a project with the CLI and checked what
nodeactually receives from the script's shell:Before the change the same project on Node 26 reported
tests 4becausetest/helper.tswas also run as a test file. I did not have a Node 20 binary available locally, so the literal-pattern failure on 20 is based on the argv shown above plus the Node changelog (glob support fornode --testadded in v21), not a run on 20.Left out on purpose:
sh,**behaves like*, so the expanded pattern only matches one directory level (test/*/*.ts). That is the same as the other templates today and covers the generated layout; I did not try to change that.npm run build:tswith TypeScript 6 (TS5011,rootDirmust be set) and ts-node can't find Node types in tests. That's unrelated to this issue; for the run above I pinnedtypescript@5in the scratch project.