Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
ascodeasice opened this issue Aug 28, 2024 · 0 comments
Open
2 tasks done

Comments

@ascodeasice
Copy link

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

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

No branches or pull requests

1 participant