fix: errorCodes import using ESM#5390
Conversation
Moving fastify errorCodes below module.exports = fastifty and also export it Signed-off-by: Melroy van den Berg <melroy@melroy.org>
jsumners
left a comment
There was a problem hiding this comment.
What is this fixing? Please provide context when opening pull requests. Also, this is missing a test.
|
It's indeed missing a test. I first wanted to know if this is what we want according to climba03003. |
Yes, it is what I said. If you need to test it, use
It is actually fixing how people can be import // Before
import Fastify from 'fastify'
const { errorCodes } = Fastify
// After
import { errorCodes } from 'fastify'The reason is behind how Node.js transform CJS to ESM named export. For anyone how interested in the details, see https://github.com/nodejs/cjs-module-lexer?tab=readme-ov-file#grammar |
Important to mention this "after" example is already documented on your fastify website (it's not yet working like this): https://fastify.dev/docs/latest/Reference/Errors/#fastify-error-codes This pr try to solve that, so it's inline with the documentation. |
|
What we need is a test. So basically create a esm-error-codes.test.mjs and import the errorCodes as mentioned in the documentation and check if it is not undefined. |
This comment was marked as outdated.
This comment was marked as outdated.
|
There are TS Type tests in Or are they ran using EDIT: Yes the |
|
The typescript typings tests are Independent from this issue. Just because you test it with tsd, you wont test it in node. |
|
It seems that the tests in I believe tap is only executing |
|
Should I extend the - 'test/**/*.test.mjs'EDIT: Done..! Now my test is running. PASS test/esm/errorCodes.test.mjs 3 OK 23.488ms
Suites: 168 passed, 168 of 168 completed |
|
Should I rename the other tests in the (This is basically unrelated fixes outside of this PR, however your ESM tests were never part of your |
|
Thanks for merging. I still would like to know what you want to do with those other ESM tests that were never part of tap? |
|
It can not harm to rename them to mjs. |
You mean But OK, I think I will create a follow-up PR to fix those other ESM tests. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
.taprcconfiguration to runtest.mjsfiles as well.test.mjsfilename?Checklist
npm run testandnpm run benchmarkand the Code of conduct
In favor of: #5388