-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Conversation
God bless you @ilteoood, this one must have been a nightmare with all the tests. |
@Fdawgs do you think there's something else I can do here? |
There was a problem hiding this 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 |
There was a problem hiding this 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?
@@ -2,7 +2,6 @@ | |||
|
|||
const t = require('tap') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 (?).
There was a problem hiding this comment.
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?
It looks like we're all good. Thanks @ilteoood for the considerable time and effort that putting this together must have taken! |
funnily, art-template decided to do a release after 6 years, and it broke CI in main. |
Checklist
npm run test
andnpm run benchmark
and the Code of conduct