typestar

Skipping and focusing in JavaScript

skip, todo and only, plus the conditional forms.

import test from "node:test";
import assert from "node:assert/strict";

test("skipped by option", { skip: "needs a database" }, () => {
  assert.fail("never runs");
});

test("skipped at run time", (t) => {
  if (process.platform === "win32") {
    t.skip("posix only");
    return;
  }
  assert.ok(process.platform.length > 0);
});

test("not written yet", { todo: true }, () => {
  assert.fail("still to do");
});

test("plain and passing", () => assert.ok(true));

How it works

  1. t.skip inside the test decides at run time.
  2. todo records intent without failing the run.
  3. only needs the runner's --test-only flag to mean anything.

Keywords and builtins used here

The run, in numbers

Lines
20
Characters to type
448
Tokens
117
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 67 seconds.

Type this snippet

Step 1 of 2 in Selecting, step 7 of 9 in Testing with node:test.

← Previous Next →