Discussion: allow extension to function when node:test is wrapped by a convenience function
#63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
My company has a 10 year old node.js codebase, and we have recently converted it to use
node:test. However, in order to successfully migrate, and for future-proofing the testing - we have wrapped thetestfunction up in our own function.We have started to work on making the codebase accessible to very junior developers, and wanted to have "click to run tests" functionality, and stumbled upon this extension. It is honestly great, but changing all of our tests to use
node:testdirectly is a bit too much to ask.Request up for discussion
I'd like to add a setting / configuration that allows for specifying a "test function override" - where you can specify where your test wrapper function is (instead of
import { test } from 'node:test';it might beimport { test } from './utils';for example ).This would allow us to use this extension for our testing with minimal changes to the codebase, and provide a single place to update if we ever switched to vitest (for example) or jest or whatever new testing framework comes around in 10 more years.
Other examples
We hit a similar problem with typescript-eslint and I thought their solution to it was elegant, where they allow specifying a callable function with a TypeOrValueSpecifier .
Proposal
I think nodejs-testing could adopt a setting that accepted a TypeOrValueSpecifier. The default value of this setting would be:
But anyone who wanted to wrap the test function would replace it with the
TypeOfValueSpecifierthat matched their wrapped test function.The code I attached to this was a very very hacky proof of concept I did to ensure it would work in theory, it is by no means a suggestion to merge this code. I just wanted to have a discussion before doing the "real" implementaiton.