bun
bun copied to clipboard
Support the `node:test` built-in API
What is the problem this feature would solve?
As part of evaluating/migrating to bun from node, it is cumbersome to use both node:test and bun:test at the same time.
What is the feature you are proposing to solve the problem?
bun should support the node:test built-in API.
What alternatives have you considered?
Maintain a separate suite or use branching logic.
Does it make sense to add a PR about it not being supported in the documentation?
My usage is to use one test code to test both bun and node compatibility. Why bun can recogonize the 'test' module?
❯ t
> [email protected] test
> bun test
bun test v1.0.25 (a8ff7be6)
test/index.test.ts:
error: Cannot find package "test" from "/Users/yutengjing/code/fetch-github-trending/test/index.test.ts"
0 pass
1 fail
Ran 1 tests across 1 files. [5.00ms]
Hey @jbergstroem do we have any solution/alias to this?
We are currently trying to run our test suite (written with node:test) using bun to ensure it works on both node.js and bun.js.
I'm not sure, but probably adding support for https://github.com/nodejs/node-core-test should be the aimed solution here.
node core test package in bun throws these two errors:
❯ bun test
bun test v1.0.30 (1424a196)
test/components.test.tsx:
[bun] Warning: async_hooks.executionAsyncId/triggerAsyncId are not implemented in Bun. It will return 0 every time.
[bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.
0 pass
0 fail
Ran 0 tests across 1 files. [601.00ms]
Node.js has published a user land package for node:test. Bun could use this to support node:test. Not sure how much work this requires to make it compatible with the bun test command and coverage reporter.
Would require deep support for async_hooks, as my above comment said.
Sadly, unless using bun's native test and jest on node is a possible solution, i couldn't find another ways to run the same test suite on both runtimes.
Would require deep support for async_hooks
Even if node:test could be just a wrapper around bun:test? I think it is what Deno is doing because running deno test is also compatible with node:test.
Maybe, but special work would be needed around matchers, since node:test uses node:assert and bun:test uses their own jest based matchers.
It looks like node:test does pretend to be bun:test now: https://github.com/oven-sh/bun/blob/main/src/js/node/test.ts
However I don't think its fully supported nicely as it uses assert from 'node:assert' instead of expect api
node:test support is currently completely broken in bun as of 1.2.18 (and I did recheck on v1.2.19-canary.29) why does bun even pretend to support it?
this should be disabled (at least in releases) until basic functionality (i.e. describe/test) works currently it appears to be present but doesn't run tests just marks anything as passing which could really confuse someone into thinking they are running tests on bun when they aren't
However I don't think its fully supported nicely as it uses
assert from 'node:assert'instead ofexpectapi
For assert I am using https://jsr.io/@std/assert instead of node:assert and my problems went away =)
I think this issue is still relevant: https://github.com/oven-sh/bun/issues/23077