Skip to content

Conversation

@matteo-gobbo
Copy link
Contributor

Hi,

The goal of this PR is migrate the tests from Tap to Node test runner, following what's been said in the issue fastify/fastify#5555

Checklist

@matteo-gobbo matteo-gobbo changed the title Migrate from tap to node Migrate from tap to Node Test Runner Mar 16, 2025
@matteo-gobbo matteo-gobbo marked this pull request as ready for review March 16, 2025 16:09
@Fdawgs
Copy link
Member

Fdawgs commented Mar 16, 2025

Thanks for the PR! .taprc also needs removing as part of this (but kept in .gitignore).

@Eomm
Copy link
Member

Eomm commented Apr 6, 2025

Could you run npm run lint:fix? it should fix the CI

@matteo-gobbo
Copy link
Contributor Author

matteo-gobbo commented Apr 6, 2025

The issue here is using const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), '')) instead of the previous t.testDir() that was implemented directly inside tap.
Do you have any suggestions about this? Perhaps there are other projects where a similar approach has been implemented that I could use as a reference?"

Thank you in advance for your answer.

@Eomm
Copy link
Member

Eomm commented Apr 13, 2025

The issue here is using const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), '')) instead of the previous t.testDir() that was implemented directly inside tap. Do you have any suggestions about this? Perhaps there are other projects where a similar approach has been implemented that I could use as a reference?"

Thank you in advance for your answer.

If i check the testdir implementation I think it was using a path in the project's folder (such as .tap/fixtures).
So I think we may not create the ostmp by a random folder in a similar way (that we must add to the gitignore)

@ilteoood
Copy link

@matteo-gobbo are you planning to complete this?

@matteo-gobbo
Copy link
Contributor Author

@matteo-gobbo are you planning to complete this?

Hi, yes sure, sorry for the delay.
I’ll work on this by the end of the week.
It's not fully clear to me how to handle the temp directory that Tap was using before.
Do you know if any of the other packages have implemented something similar?

@ilteoood
Copy link

What suggested by @Eomm is a good starting point. At the moment there's no other project that has been migrated that used testdir. But if you check your inner implementation as suggested, it doesn't anything special. You just need to point to the right path.
Let me know if you need additional help, I'll try to provide additional support if you can't figure it out.

@matteo-gobbo
Copy link
Contributor Author

What suggested by @Eomm is a good starting point. At the moment there's no other project that has been migrated that used testdir. But if you check your inner implementation as suggested, it doesn't anything special. You just need to point to the right path.

Let me know if you need additional help, I'll try to provide additional support if you can't figure it out.

I’m actually out for the next couple of days, but I’ll give it a try as soon as I’m back.
Thanks for your help!

@matteo-gobbo matteo-gobbo force-pushed the migrate-from-tap-to-node branch from d029f7b to 86f96ea Compare August 23, 2025 06:57
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm other than these

@matteo-gobbo
Copy link
Contributor Author

Hi @gurgunday, thanks for your suggestions!
I've replaced deepEqual with deepStrictEqual also in multipart-attach-body.test.js.

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

@gurgunday gurgunday requested review from a team and Fdawgs August 26, 2025 20:53
@matteo-gobbo
Copy link
Contributor Author

Hi @is2ei, I've update the error assertion to use ifError.
I also updated the test should throw fileSize limitation error on small payload which had been skipped before my implementation and marked with a FIXME.
My misuse of t.assert.ok made it seem to work, but it wasn’t correct.
I followed the same approach used in another test, please check if this looks good to you.

@matteo-gobbo matteo-gobbo force-pushed the migrate-from-tap-to-node branch from 684df83 to 47145bd Compare August 30, 2025 09:01
Copy link
Contributor

@is2ei is2ei left a comment

Choose a reason for hiding this comment

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

LGTM!

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

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

@gurgunday
Copy link
Member

gurgunday commented Sep 3, 2025

Can you rebase and fix conflicts?

@matteo-gobbo matteo-gobbo force-pushed the migrate-from-tap-to-node branch from 47145bd to 3c40164 Compare September 3, 2025 22:13
@mcollina mcollina merged commit 47f6965 into fastify:main Sep 4, 2025
14 checks passed
@p-kuen
Copy link

p-kuen commented Sep 4, 2025

In this PR the c8 package was added to the dependencies instead of just dev dependencies. I think it would be enough to add it to the dev dependencies as it is just used in a script. What do you think?

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 4, 2025

@p-kuen

Please provide a PR to move c8 to devDependencies.

@Eomm
Copy link
Member

Eomm commented Sep 4, 2025

@fastify/collaborators Please - be mindful that we should put extra care when editing the package.json

@simoneb simoneb requested a review from Copilot September 4, 2025 11:47
@simoneb
Copy link
Contributor

simoneb commented Sep 4, 2025

I asked a review from Copilot to see if it would have caught it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the test suite from TAP (Test Anything Protocol) to Node's built-in Test Runner, modernizing the testing infrastructure in line with current Node.js best practices.

  • Updates all test files to use node:test instead of tap
  • Replaces TAP-specific assertions with Node's native t.assert methods
  • Adjusts test function signatures to accommodate Node Test Runner patterns

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/stream-consumer.test.js Basic migration with assertion replacements
test/multipart.test.js Large test file with callback pattern updates
test/multipart-*.test.js Multiple multipart test files with assertion and teardown changes
test/generate-id.test.js Simple utility test migration
test/fix-313.test.js Bug fix test migration
test/big.test.js Performance test with callback handling updates
package.json Build configuration updates removing tap dependency
.taprc Removed TAP configuration file

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// FIXME, this test fail
test('should throw fileSize limitation error on small payload', { skip: true }, async function (t) {
test('should throw fileSize limitation error on small payload', async function (t) {
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The test was previously skipped but is now enabled without removing the skip condition comment. This could cause tests to fail unexpectedly since the original comment indicated this test was broken.

Suggested change
test('should throw fileSize limitation error on small payload', async function (t) {
// Previously skipped due to known issue; re-enabled after confirming fix.
test('should throw fileSize limitation error on small payload', { skip: process.platform === 'win32' }, async function (t) {

Copilot uses AI. Check for mistakes.
Comment on lines 20 to 21
t.plan(9)

Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Using t.plan() with done callback is redundant in Node Test Runner. The test will automatically complete when done() is called, making the plan unnecessary and potentially confusing.

Suggested change
t.plan(9)

Copilot uses AI. Check for mistakes.
Comment on lines +481 to +482
test('should throw error due to file size limit exceed (Default: true)', function (t, done) {
t.plan(7)
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The plan count was increased from 6 to 7 but only 6 assertions are visible in the test. This will cause the test to hang waiting for the 7th assertion that never comes.

Suggested change
test('should throw error due to file size limit exceed (Default: true)', function (t, done) {
t.plan(7)
t.plan(6)

Copilot uses AI. Check for mistakes.
Comment on lines +531 to +532
test('should not throw error due to file size limit exceed - files setting (Default: true)', function (t, done) {
t.plan(6)
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The plan count was increased from 5 to 6 but only 5 assertions are visible in the test. This will cause the test to hang waiting for the 6th assertion that never comes.

Copilot uses AI. Check for mistakes.
const fs = require('node:fs')
const { access } = require('node:fs').promises
const EventEmitter = require('node:events')
// const os = require('node:os')
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

This commented import should be removed as it serves no purpose and clutters the code.

Suggested change
// const os = require('node:os')

Copilot uses AI. Check for mistakes.
Comment on lines 241 to +248

fastify.post('/', async function (req, reply) {
t.ok(req.isMultipart())
t.assert.ok(req.isMultipart())

try {
await req.saveRequestFiles({ tmpdir })
// temp file saved, remove before the onResponse hook
await fs.promises.rm(tmpdir, { recursive: true, force: true })
fs.rmSync(tmpdir, { recursive: true, force: true })
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

This replaces t.testdir() but doesn't ensure the temporary directory is cleaned up after the test, which could lead to test artifacts remaining on the filesystem.

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +99
const req = http.request(opts, (res) => {
res.on('data', () => {})

res.on('end', () => {
fastify.close(() => {
done()
})
})
})
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The response handling has been changed to call done() inside the fastify.close() callback, but this creates a race condition. If the pump operation fails, done() will never be called, causing the test to hang.

Copilot uses AI. Check for mistakes.
@simoneb
Copy link
Contributor

simoneb commented Sep 4, 2025

Looks like it didn't catch it 🤷

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.