Files
openidea/fixtures/node-test-app/test/inventory.test.js
T
LU XIANGRUIandwildcatDownstairs 8e541d5b45 feat(run): run node:test tests with a test tree and Rerun Failed Tests (#5172)
`node --test` runs showed no test tree, and single tests ran with Jest's `-t`.

- Detection: a `package.json` script whose Node options include `--test` (also `tsx --test`) is a test configuration with `testRunner: "node-test"`; a script that picks its own `--test-reporter` runs as written.
- Test tree: test runs add the IDE's reporter (`nodeTestReporter.js`, passed as a `data:` URL) next to `spec` through `NODE_OPTIONS`, which works through `npm run`, Node's per-file child processes and remote run targets. It prints a record per test (file, describe chain, status, duration, declaration line, error); the records become the tree and are hidden from the console, which keeps `spec`'s output.
- Gutter, Rerun Failed Tests, run selected tests: select by full name with `--test-name-pattern` in `NODE_OPTIONS`, plus the files.

New fixture `fixtures/node-test-app`, run by `smoke/run.test.ts` in the TypeScript job.

Closes #5152

Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
2026-11-22 15:19:57 +08:00

28 lines
900 B
JavaScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { Inventory } from "../src/inventory.js";
describe("inventory", () => {
it("counts received stock", () => {
assert.equal(new Inventory().receive("mug", 3).receive("mug", 2).count("mug"), 5);
});
describe("shipping", () => {
it("takes items out of stock", () => {
assert.equal(new Inventory().receive("mug", 3).ship("mug", 2).count("mug"), 1);
});
it("refuses more than is in stock", () => {
assert.throws(() => new Inventory().ship("mug", 1), /not enough mug/);
});
});
it("intentionally fails (set OPENIDEA_FAIL=1)", { skip: !process.env.OPENIDEA_FAIL }, () => {
assert.equal(new Inventory().receive("mug", 1).count("mug"), 2);
});
});
it("rejects non-positive quantities", () => {
assert.throws(() => new Inventory().receive("mug", 0), RangeError);
});