Description
Since Node.js, Bun and Deno offer different APIs (node:test
, bun:test
, Deno.test
) but have many similarities, would it make sense to have a set of specced cross-platform testing APIs?
Motivating Example
runtime:
prefix, in the style of Node.js or Bun:
import { test } from 'runtime:test';
test('2 + 2', () => {
expect(2 + 2).toBe(4);
});
Or, Deno-style global:
Runtime.test("assert works correctly", () => {
assert(true);
assertEquals(1, 1);
});
// Using existing global:
globalThis.test("assert works correctly", () => {
assert(true);
assertEquals(1, 1);
});
This was originally inspired by @nzakas's tweet here:
What I want: To write JavaScript tests once and be able to run them across Node.js, Bun, and Deno.
Problem: Bun and Deno have built-in test runners you have to import from to run tests. I use Mocha. This doesn't work.
Solution: ???
Source: https://twitter.com/slicknet/status/1762264774166085937
@CanadaHonk rightly mentions that, while there are similarities, there are probably challenges creating a spec:
most test framework APIs are pretty similar?
probably hard to spec due to sandbox/isolation/etc
Source: https://twitter.com/CanadaHonk/status/1762417370893516929
Alternatives Considered
Separate Package
Instead of something built into the standard library of multiple runtimes, use a separate package (either like Vitest, including testing features of its own, or a wrapper package).
Downsides:
- Doesn't work out of the box or with zero dependencies
- Downloading and maintaining another package in
devDependencies