DEV Community 👩‍💻👨‍💻

Adam Crockett
Adam Crockett

Posted on

✅ node.js Test Framework now in core modules

DOCS

Good gravy! Node has a test framework, Now what does that actually mean?

You download Jest and test right? well what if you could just

import assert from 'assert';
import test from 'node:test';

test('a description', () => {
  assert.strictEqual(1, 1);
});

Enter fullscreen mode Exit fullscreen mode

output:

(node:27143) ExperimentalWarning: The test runner is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
TAP version 13
ok 1 - a
  ---
  duration_ms: 0.000279472
  ...
1..1
# tests 1
# pass 1
# fail 0
# skipped 0
# todo 0
# duration_ms 0.050426448
Enter fullscreen mode Exit fullscreen mode

Agh, a reporter only a mother could love!

Sidenote

Thats exactly how Rust handles its tests, there is no framework and usually all tests in the same file as the source which is actually really nice.

What does it mean?

Node.js is shooting for you to forget Jest, will you? maybe one day, now? no!

But it's a step in the right direction standardising testing is a very good idea.

Oldest comments (0)

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.