js/test/sim

js/test/sim.ts

fino:test/sim — test-owned cassette storage for deterministic simulations.

simulate() from fino:sim owns execution, recording, and replay. This module adds only test storage policy: the first run records transport frames in a JSON file named after the test, and later runs replay that file. Delete the cassette deliberately when changed behavior should be recorded again.

import { describe, it } from 'fino:test/test';
import { simulated } from 'fino:test/sim';

describe('checkout', () => {
  it('charges once', async (t) => {
    const report = await simulated(t, {
      entry: './checkout.ts',
      world: { 'app:payments': { charge: async () => ({ ok: true }) } },
    });
    t.equal(report.journal.calls('app:payments', 'charge').length, 1);
  });
});

Interfaces

interface SimTestContext {

Test identity required to assign ownership of a cassette file.

Readonly Properties

readonly name: string

Full test name used to derive the default cassette basename.

interface SimulatedOptions extends Omit<SimulateOptions, 'cassette'> {

Options for a simulation whose cassette belongs to one test.

Properties

cassetteDir?: string

Directory containing cassettes. Defaults to ./__cassettes__ from the Realm cwd.

cassetteName?: string

Cassette basename without .json. Defaults to a slug of the full test name.

noCassette?: boolean

Run against the live world without reading or writing cassette storage.

Functions

async function simulated<Result = unknown>( context: SimTestContext, options: SimulatedOptions, ): Promise<SimReport<Result>>

Run a deterministic simulation using the cassette owned by context.name.

An absent cassette is recorded and written after a successful run. An existing cassette is replayed without invoking its live providers. Invalid, unreadable, or divergent cassettes fail the test and remain untouched.