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

(test): migrate to node test runner #461

Merged
merged 31 commits into from
Mar 12, 2025
Merged

(test): migrate to node test runner #461

merged 31 commits into from
Mar 12, 2025

Conversation

ilteoood
Copy link
Contributor

@ilteoood ilteoood commented Mar 9, 2025

Checklist

Sorry, something went wrong.

@Fdawgs
Copy link
Member

Fdawgs commented Mar 9, 2025

God bless you @ilteoood, this one must have been a nightmare with all the tests.

@ilteoood ilteoood requested a review from Fdawgs March 10, 2025 07:22

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@ilteoood
Copy link
Contributor Author

@Fdawgs do you think there's something else I can do here?

@Fdawgs Fdawgs requested a review from Copilot March 11, 2025 19:35
Copy link

@Copilot 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 using the Tap test runner and simple-get to using Node’s built-in test runner and fetch. Key changes include:

  • Converting tests from callback-based to async/await style
  • Replacing simple-get HTTP calls with fetch
  • Updating snapshot tests accordingly

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

File Description
test/test.js Migrated tests to async/await and node:test; replaced simple-get
test/test-import-engine.mjs Updated to async test style and use fetch instead of callbacks
test/snap/test-ejs-with-snapshot.js Adjusted asynchronous handling and snapshot assertions
benchmark.js Replaced simple-get with fetch for the warmup request

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

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

It's a big boofer but lgtm. Will need a few more extra pair of eyes as I no doubt glossed over some bits.

I know we don't track coverage in this repo's tests, but is coverage percentage still the same after migrating?

@Fdawgs Fdawgs requested a review from a team March 11, 2025 19:44
@@ -2,7 +2,6 @@

const t = require('tap')
Copy link

Choose a reason for hiding this comment

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

I see that tap is still being used here. Was this intentional? If so, it would have been useful if you had mentioned it in the PR description

Copy link
Contributor Author

@ilteoood ilteoood Mar 11, 2025

Choose a reason for hiding this comment

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

I mentioned it in one of the previous comments. It was not intended

Copy link

Choose a reason for hiding this comment

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

Ok, please consider that a reviewer will not be able to see resolved conversations unless they are explicitly opened, which is why I missed it.

@@ -93,7 +95,6 @@
"nunjucks": "^3.2.4",
"pino": "^9.0.0",
"pug": "^3.0.2",
"simple-get": "^4.0.1",
"split2": "^4.2.0",
"tap": "^21.0.0",
Copy link

Choose a reason for hiding this comment

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

why is tap not being removed from dev dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On node 20 snapshots are not available yet, so I cannot remove it for those tests yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
test('reply.view with art-template engine and custom templates folder', t => {
t.plan(6)
test('reply.view with art-template engine and custom templates folder', async t => {
t.plan(4)
Copy link

Choose a reason for hiding this comment

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

since there are no more assertions in callbacks, all the t,plan can be removed as they don't offer any value and just overspecify the tests. unless there is a specific reason why you left them in place, I would suggest to remove them from here and everywhere else you removed the assertions in callbacks (which is probably everywhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left them just because everywhere else in the Fastify org they have been maintained even if the tests have been migrated. I'm ok with removing them, but I want to be 100% sure that it is something that we want to do, according also the amount of tests that I need to change

Copy link

Choose a reason for hiding this comment

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

yep fair point. I personally don't see any use in them if the tests are using async/await. the only reason for them to be there previously was to prevent the test from finishing until all the assertions running in callbacks had executed, hence no reason in my opinion to leave them there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's see what @Eomm or @Fdawgs think about it. They have reviewed most of my PRs in other repos so I guess they are the best people to ask what they prefer

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @simoneb but then again if I recall correctly there were maintainers who wanted to use them anyway so it might be better to wait for their input on this one :)

And like @ilteoood mentioned we currently use them in most places

Copy link
Member

Choose a reason for hiding this comment

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

I think it is out of scope of the migration to the node test runner.
There are a lot of improvements we could write and removing the plan adds confusion to junior contributors IMHO.

For the logs:
In general I prefer to keep the plan because it "forces" the devs to STOP and THINK before writing the test.

since there are no more assertions in callbacks

Let's do an example: the double genPromise is a typo but:

  • with plan: I can find it
  • without plan: the test would be green
const { test } = require('node:test');
test('test', async (t) => {
  t.plan(1)

  async function genPromise () {
    t.assert.ok(true)
  }

  await genPromise()
  await genPromise()
})

Another example: If we have an assertion on a Fastify hook and, due to a bug, we can spot a double execution of that function.


Note: the subject test does not have assertion on a callback function executed by the framework itself, so it would be safe to remove it.. but then if someone adds a new assertion on a callback we (maintainers) should check if the plan is set... etc.. useless back and forth to save one line (?).

Copy link

Choose a reason for hiding this comment

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

I do not agree with this but I don't have a strong opinion either. Also, I see the value in consistency and if other repos are using the same approach, it does make sense to keep it instead of creating an exception.

I certainly do see an activity in the future of removing all t.plan from the whole codebase though. If you can spare writing unnecessary code, I'd say why not?

@simoneb
Copy link

simoneb commented Mar 12, 2025

It looks like we're all good. Thanks @ilteoood for the considerable time and effort that putting this together must have taken!

@simoneb simoneb merged commit 5cb3b72 into fastify:main Mar 12, 2025
11 checks passed
@simoneb
Copy link

simoneb commented Mar 12, 2025

funnily, art-template decided to do a release after 6 years, and it broke CI in main.

https://github.com/goofychris/art-template/issues/658

@Fdawgs Fdawgs mentioned this pull request Mar 16, 2025
2 tasks
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.

None yet

5 participants