// The assert surface's honest fences: legacy deepEqual/notDeepEqual // (shallow equal/notEqual and assert/strict's same-named aliases lower), // reference-equality strictEqual on objects, // union operands (narrow first), mismatched or uncomparable deep types // (typed arrays, class instances), namespace-object calls, unsupported // throws/rejects expectations (properties outside the static error // surface, empty shapes, non-literal objects, doesNotReject shapes — // Node's own TypeError), ifError over uncomparable types, and assert // functions as values. Every reached site terminates in a named // diagnostic — never a miscompare, never silence. import assert from "node:assert"; import * as assertNs from "node:assert"; assert.equal(1, 1); // shallow legacy equality lowers for primitives assert.notEqual(1, 2); assert.deepEqual([1], [1]); assert.notDeepEqual([1], [2]); const box = { n: 1 }; assert.strictEqual(box, box); // reference equality — deepStrictEqual hint let maybe: string | undefined = "x"; if ("x".length === 0) maybe = undefined; assert.strictEqual(maybe, "x"); // union operand — narrow first const unk: unknown = JSON.parse("{}"); assert.strictEqual(unk, { n: 1 }); // strict + composite static side: reference identity does not survive the unknown boundary assert.deepStrictEqual(unk, new Uint8Array([1])); // bytes static side: the dyn copy cannot carry the brand assert.deepStrictEqual(unk, new Map()); // not dyn-convertible assert.deepStrictEqual([1, 2], ["a", "b"]); // different static types assert.deepStrictEqual([new Uint8Array([1])], [new Uint8Array([1])]); // NESTED typed arrays fence (no brand in the element type) class Point { x: number; constructor(x: number) { this.x = x; } } assert.deepStrictEqual(new Point(1), new Point(1)); // class instances fence assertNs(true); // namespace objects are not callable in Node assert.throws(() => { throw new Error("x"); }, { errno: -2 }); // properties outside the static error surface assert.throws(() => { throw new Error("x"); }, {}); // Node rejects the empty shape // (a convertible record VARIABLE as the expected shape lowers now — the // errValue key walk; corpus 2556 pins it) void assert.doesNotReject(async () => {}, { name: "TypeError" }); // Node's own TypeError (function or RegExp only) assert.ifError(new Map()); // no honest ifError rendering for this type const eq = assert.strictEqual; // assert functions as values eq(1, 1);