Skip to content

Fix: Test script cannot detect test under test directory with deep level#708

Merged
mcollina merged 6 commits intofastify:masterfrom
adamward459:fix-test-script
Feb 23, 2024
Merged

Fix: Test script cannot detect test under test directory with deep level#708
mcollina merged 6 commits intofastify:masterfrom
adamward459:fix-test-script

Conversation

@adamward459
Copy link
Contributor

Checklist

System information

The demo can be found here
Mac os: 14.3.1 (23D60)
Node: v21.6.2
Npm: 10.2.4

Reproduce

List all tests under the test directory

➜  demo-fastify git:(main) find ./test -name "*.test.ts"
./test/plugins/support.test.ts
./test/routes/example.test.ts
./test/routes/root.test.ts
./test/routes/routes/example.test.ts
./test/routes/routes/root.test.ts
./test/routes/routes/routes/example.test.ts
./test/routes/routes/routes/root.test.ts

Run test command, the test command can only figure out files at first level.

➜  demo-fastify git:(main) npm test

> demo-fastify@1.0.0 test
> npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register test/**/*.ts


> demo-fastify@1.0.0 build:ts
> tsc

✔ support works standalone (9.705125ms)
✔ example is loaded (3074.605459ms)
✔ default root route (3067.900959ms)
ℹ tests 3
ℹ suites 0
ℹ pass 3
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4618.984375
--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------|---------|----------|---------|---------|-------------------
All files           |     100 |      100 |     100 |     100 |                   
 src                |     100 |      100 |     100 |     100 |                   
  app.ts            |     100 |      100 |     100 |     100 |                   
 src/plugins        |     100 |      100 |     100 |     100 |                   
  sensible.ts       |     100 |      100 |     100 |     100 |                   
  support.ts        |     100 |      100 |     100 |     100 |                   
 src/routes         |     100 |      100 |     100 |     100 |                   
  root.ts           |     100 |      100 |     100 |     100 |                   
 src/routes/example |     100 |      100 |     100 |     100 |                   
  index.ts          |     100 |      100 |     100 |     100 |                   
--------------------|---------|----------|---------|---------|-------------------

After I change the pattern to include double quote mark, here is the result:

➜  demo-fastify git:(main) ✗ npm test

> demo-fastify@1.0.0 test
> npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"


> demo-fastify@1.0.0 build:ts
> tsc

✔ test/helper.ts (2398.497417ms)
✔ support works standalone (9.181417ms)
✔ example is loaded (4585.684167ms)
✔ default root route (4705.922125ms)
✔ example is loaded (4690.084708ms)
✔ default root route deep (4674.864291ms)
✔ example is loaded (4636.318958ms)
✔ default root route (4657.602333ms)
ℹ tests 8
ℹ suites 0
ℹ pass 8
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 7223.8055
--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------|---------|----------|---------|---------|-------------------
All files           |     100 |      100 |     100 |     100 |                   
 src                |     100 |      100 |     100 |     100 |                   
  app.ts            |     100 |      100 |     100 |     100 |                   
 src/plugins        |     100 |      100 |     100 |     100 |                   
  sensible.ts       |     100 |      100 |     100 |     100 |                   
  support.ts        |     100 |      100 |     100 |     100 |                   
 src/routes         |     100 |      100 |     100 |     100 |                   
  root.ts           |     100 |      100 |     100 |     100 |                   
 src/routes/example |     100 |      100 |     100 |     100 |                   
  index.ts          |     100 |      100 |     100 |     100 |                   

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@adamward459
Copy link
Contributor Author

Can you retry the window job @mcollina ? i don't know what went wrong with it

@adamward459 adamward459 requested a review from mcollina February 23, 2024 11:52
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit ce0cfea into fastify:master Feb 23, 2024
@dt-atkinson
Copy link

This change seems to break node versions <21 for me when running npm test on MacOS zsh terminal. node --test doesn't seem to support glob expansion prior to node 21.

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.

3 participants