testing library

Testing toolkit for code that uses wasmforge.

Everything here works without a browser except the two JS-interop helpers (FakeJsEnvironment, createJsLoopbackTransport), which are real only under a web compiler (dart test -p chrome) and throw UnsupportedError with guidance elsewhere.

Typical VM unit test:

import 'package:test/test.dart';
import 'package:wasmforge/testing.dart';

void main() {
  tearDown(clearCapabilityOverrides);

  test('my code falls back when not isolated', () {
    setCapabilityOverridesForTesting(
      const CapabilityOverrides(crossOriginIsolated: false),
    );
    // exercise code that checks isCrossOriginIsolated ...
  });
}

Classes

CapabilityOverrides
Test-only overrides consulted before real platform detection.
FakeJsEnvironment
Web-only fake JS environment; on non-web platforms every method throws UnsupportedError with guidance.
FakeSharedBuffer
A SharedBuffer backed by ordinary process memory, for VM tests.
FakeWorkerTransport
A scriptable WorkerTransport for unit-testing pool/protocol logic on the VM: executes tasks from a TaskRegistry in-process while letting the test inject spawn failures, latency, task failures, and crashes — and records everything that was sent.

Functions

clearCapabilityOverrides() → void
Removes any overrides installed by setCapabilityOverridesForTesting.
createJsLoopbackTransport(TaskRegistry registry) WorkerTransport
Web-only loopback transport; throws UnsupportedError here.
setCapabilityOverridesForTesting(CapabilityOverrides? overrides) → void
Installs capability overrides for tests; pass null to remove them.
simulateStructuredClone(Object? payload) Object?
Deep-copies payload with the same semantics the structured clone algorithm applies to protocol payloads: containers and typed data are copied, SharedBuffers are passed through by reference (their memory is shared), and unsupported values throw ArgumentError.