Skip to content

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

Open
@ascodeasice

Description

@ascodeasice

Prerequisites

  • I have written a descriptive issue title
  • 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:

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:

- "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 #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions