fastify / fastify/fastify-cli

Typescript Fastify app generated with cli has error when running `npm run test`

Open
#756 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
733
Forks
177
Avg merge
1d 20h
Merged PRs (30d)
3

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported

### Fastify version

4.28.1

### Plugin version

_No response_

### Node.js version

18.20.4

### Operating system

Linux

### Operating system version (i.e. 20.04, 11.3, 10)

Linux Mint 21.3

### Description

After running the following commands:

```bash
fastify generate fastify-test --lang=ts
cd fastify-test
npm install
```

I encountered an error when executing the `npm test` command:

> Could not find '/home/leo/test/fastify-test/test/**/*.ts'

To fix this issue, I modified the `test` script in `package.json` by removing the double quotes around the file path:

```diff
- "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",
```

After making this change, the error was resolved, and the tests ran without issues.

Upon further investigation, I discovered PR https://github.com/fastify/fastify-cli/pull/708 and learned that for Node.js versions prior to 21, commands with double quotes around file paths don't work correctly, and such versions (without double quotes) can only identify files at the first directory level. However, in Node.js versions 21 and later, commands work both with and without double quotes. Moreover, using double quotes allows files at deeper directory levels to be recognized.

**TL;DR:** To run tests reliably, use Node.js version 21 or newer.

### Link to code that reproduces the bug

_No response_

### Expected Behavior

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.