Skip to content
Logo
ghostry

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.

npm install @ghostry/extern
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 spyArrow
= ().({ : 1, : "Ada" });
((await (1)).).("Ada"); (.[0]?.).(1); }); });