
extern
Mock calls to external systems without changing a signature.
Wrap a network call, a query, or a metric where it happens. Outside tests it runs as written. Inside a testing block it returns the typed value you mocked, and records how it was called.
import { } from "@ghostry/extern";
import { , } from "bun:test";
const = ();
type = { : number; : string };
export const = .<>();
// Source: the call is wrapped where it happens, and the signature is unchanged.
export const = (: number) =>
.
.()
.()
.(async () => {
const = await (`https://api.example.com/users/${}`);
return (await .()) as ;
});
// Test: no request is made, and the spy records the call.
("loads a user", async () => {
await .(async () => {
const spy = ().({ : 1, : "Ada" });
((await (1)).).("Ada");
(.[0]?.).(1);
});
});A wrapped call keeps its function's signature. Nothing is threaded through constructors or arguments to make it replaceable.
A block names its result type with an identity, and its mock must be a value of that type. TypeScript checks every mock against the code it replaces.
Inside a testing block, an unmocked value block throws, and a mock that is never used fails the test. Every external call in a test is accounted for.
Each mock returns a spy recording every call it served: the data passed in with given, and what the block returned or threw.
With harness, every test body is a testing block, and its mocker arrives on the test context. No extern.testing wrapper in each test.
An extension lets a block built from another library's schema produce its own value. With fabricator's, a typed block needs no mock at all.