TAU/ DOCS

Testing Utilities

Public-client test harnesses, mocks, and geometry assertions for runtime plugin authors.

@taucad/runtime-testing provides a real in-process RuntimeClient harness, Vitest-backed mocks, glTF inspection, and geometry assertions. Install it as a development dependency; Vitest and @taucad/runtime are required peers.

npm install -D @taucad/runtime-testing vitest

Types

Prop

Type

Runtime Harnesses

FunctionDescription
createTestRuntimeClientCreate a real client over inProcessTransport with an isolated in-memory filesystem
createTestGeometryRender one fixture with the runtime's typed open request and optional named-view callback; close the client before returning
getTestParametersResolve one fixture's parameter schema through a temporary client and shut it down afterward
describeBundlerConformanceRun the shared bundler conformance suite against a custom bundler definition

Callers own clients returned by createTestRuntimeClient and must call shutdown(). The two convenience helpers own and close the clients they create.

Runtime Mocks and Assertions

FunctionDescription
createMockLoggerCreate a Vitest-backed runtime logger
createMockFileSystemCreate a configurable kernel filesystem
createMockKernelRuntimeCreate a direct kernel-definition runtime
createMockRuntimeCreate a middleware runtime with filesystem, state, and hashes
createMockRuntimeClientCreate an explicit RuntimeClient mock
createMockDependenciesCreate standard dependency records
createMockCreateGeometryHandlerCreate a middleware geometry handler
createMockGetParametersHandlerCreate a middleware parameter handler
createErrorResultCreate a failed geometry result
assertSuccess / assertFailureAssert and narrow a kernel result
assertRenderingSuccessAssert and narrow a public document rendering
createMockInputCreate a middleware geometry request
createGeometryFileCreate a normalized file locator for direct definition unit tests

Geometry Validation

validateGlbData, glbToDocument, getInspectReport, getGeometryStatsFromInspect, and getBoundingBoxFromInspect inspect binary glTF. extractGltfFromResult, extractGltfFromExportResult, createGeometryTestHelpers, createGeometryVariant, and getSignedVolumeFromGlb work over runtime results, alongside shared color, coordinate, and naming assertions.

Usage

import { afterEach, describe, expect, it } from 'vitest';
import { esbuild } from '@taucad/esbuild';
import { replicad } from '@taucad/replicad';
import { assertRenderingSuccess, createGeometryTestHelpers, createTestRuntimeClient } from '@taucad/runtime-testing';
import { defineRuntime } from '@taucad/runtime/worker';

const runtime = defineRuntime({
  plugins: [replicad({ kernels: { default: { wasm: 'single' } } }), esbuild()],
});

describe('kernel test', () => {
  const clients = new Set<ReturnType<typeof createTestRuntimeClient>>();

  afterEach(async () => {
    await Promise.all([...clients].map((client) => client.shutdown()));
    clients.clear();
  });

  it('renders geometry through the production client path', async () => {
    const client = createTestRuntimeClient({
      runtime,
      files: {
        'main.ts': `
          import { makeBaseBox } from 'replicad';
          export default () => makeBaseBox(10, 20, 30);
        `,
      },
    });
    clients.add(client);

    const document = client.open({ source: { path: 'main.ts' } });
    const view = document.view('model');
    const outcome = await view.rendering();
    expect(outcome.superseded).toBe(false);
    if (outcome.superseded) return;

    assertRenderingSuccess(outcome.rendering);
    await createGeometryTestHelpers().expectValidGltf(outcome.rendering);
    view.close();
    document.close();
  });
});

On this page