* no this does not involve npm, it just made the title look good 🤷

NodeJS v16.17 / v18 introduced a new module named node:test which includes basic test scaffolding! This makes it real easy to whip up a super-basic JS test file and iterate on it, without having to set up a framework like Mocha or Jest.

Save this to a file named with a .mjs extension, e.g. test.mjs:

import {strictEqual} from 'assert'
import {test} from 'node:test';

test('runs a thing', () => {
  strictEqual('foo', 'bar')

…then if you’ve got Node >= 16.17.0 || >= 18.0.0 you’ll be able to:

$ node ./test.mjs
# Subtest: runs a thing
not ok 1 - runs a thing
  duration_ms: 1.016333
  failureType: 'testCodeFailure'
  error: |-
    Expected values to be strictly equal:
    'foo' !== 'bar'
  stack: |-
    TestContext.<anonymous> (file:///test
    Test.runInAsyncScope (node:async_hooks:203:9)
    Test.run (node:internal/test_runner/test:486:25)
    Test.start (node:internal/test_runner/test:413:17)
    test (node:internal/test_runner/harness:129:18)
    ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    async Promise.all (index 0)
    async ESMLoader.import (node:internal/modules/esm/loader:530:24
    async loadESM (node:internal/process/esm_loader:91:5)

(Note that with Node 16.19.1 using this module will also spit out a helpful warning: (node:8518) ExperimentalWarning: The test runner is an experimental feature. This feature could change at any time…)