API reference@evolu/commonTest › testCreateRun

Call Signature

function testCreateRun(): Run<TestDeps>;

Defined in: packages/common/src/Test.ts:141

Creates a test Run with deterministic default deps or optional custom deps.

Use this as the default composition root in tests. Each call creates fresh TestDeps via testCreateDeps, then merges any provided custom deps.

Example

// Built-in TestTime
await using run = testCreateRun();
const fiber = run(sleep("1s"));
run.deps.time.advance("1s");
await fiber;

// For a single test, create the dependency using the Run.
await using run = testCreateRun();
await using foo = await run.orThrow(createFoo());
const runWithFoo = run.addDeps({ foo });

expect(runWithFoo.deps.foo).toBe(foo);

// If multiple tests need the same setup, create a disposable helper.
// Then `await using setup` disposes everything the helper owns.
const setupFoo = async () => {
  await using stack = new AsyncDisposableStack();
  const run = stack.use(testCreateRun());
  const foo = stack.use(await run.orThrow(createFoo()));
  const moved = stack.move();

  // Return whatever the tests need: a Run with the dependency,
  // the dependency itself, or both.
  return {
    run: run.addDeps({ foo }),
    foo,
    [Symbol.asyncDispose]: () => moved.disposeAsync(),
  };
};

await using setup = await setupFoo();
const { run, foo } = setup;
expect(run.deps.foo).toBe(foo);

Name reusable setup helpers after what they set up:

  • setupFoo for reusable test setup for Foo
  • testSetupFoo when a library module exports the helper as part of its public test API, e.g. testSetupSqlite.

Call Signature

function testCreateRun<D>(
  deps: D,
): Run<
  Omit<RunDeps, "time" | "console"> &
    TestConsoleDep &
    TestTimeDep &
    RandomLibDep &
    D
>;

Defined in: packages/common/src/Test.ts:144

With custom dependencies merged into TestDeps.