What is the problem this feature will solve?
The using keyword is perfect for creating resources in tests. It would be great if this can be used with module.registerHooks() to test these hooks.
import { registerHooks } from 'node:module'
import { test } from 'node:test'
import { createHooks } from 'my-package'
test('my hook works', () => {
using _ = registerHooks(createHooks())
})
This was also suggested in #55698 (comment), but that was over a year ago. Times have changed. I’d like to believe the using keyword will start to become more integrated.
What is the feature you are proposing to solve the problem?
I suggest to replace the module.registerHooks() return value with a disposable (object with a Symbol.dispose key).
What alternatives have you considered?
Alternatively the return deregister value can be kept as a function, but this function could be assigned the Symbol.dispose key, which would be a reference to itself.
What is the problem this feature will solve?
The
usingkeyword is perfect for creating resources in tests. It would be great if this can be used withmodule.registerHooks()to test these hooks.This was also suggested in #55698 (comment), but that was over a year ago. Times have changed. I’d like to believe the
usingkeyword will start to become more integrated.What is the feature you are proposing to solve the problem?
I suggest to replace the
module.registerHooks()return value with a disposable (object with aSymbol.disposekey).What alternatives have you considered?
Alternatively the return deregister value can be kept as a function, but this function could be assigned the
Symbol.disposekey, which would be a reference to itself.