Skip to content

@xstate/test@2.0.0-beta.5

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 02 Dec 18:21
b40d5a7

Minor Changes

  • d3da571: Coverage now reports which branch of a function transition ran. The new transitionTargets dimension records each transition with the target state nodes it resolved to, so a function transition that returns different targets gets one id per branch:

    const { coverage } = await testPaths(checkoutMachine, { fromEvents });
    
    coverage.transitionTargets.covered;
    // ['["transitionTarget","checkout.review","PLACE_ORDER",0,["checkout.confirmed"]]', ...]
    
    assertTestCoverage(coverage, { transitionTargets: 1 });

    Static transitions are declared up front with their config targets. Function transition branches appear once a run takes them.

    State nodes and transitions that are reachable only through function transitions are no longer reported as unknown after a run visits them. A visited state node, the state nodes reachable from it through config targets, and the transitions out of them are reported as uncovered until a run covers them.

    Static reachability now treats the ancestors of a nested transition target as active, so their transitions are no longer reported as unreachable or unknown. State nodes that a start snapshot activates, and state nodes a run passes through within one step, also count as visited for reachability.

Patch Changes

  • b26ff57: Add unknown: 'fail' to coverage assertions and coverage-based stop conditions. A gated dimension with unknown entries cannot pass.

    assertTestCoverage(coverage, {
      transitions: 1,
      stateNodes: 1,
      unknown: 'fail'
    });

    Use strictReplay: true with fromEvents to reject unhandled events before the system under test starts. Supply strictReplay.allowUnhandled for intentional no-ops.

    Use assertTestCoverage(coverage, { sutComparisons: 1 }) to require at least one observation comparison. Playwright sessions release listeners and tracing when reset fails.

  • 001502b: testPaths() from @xstate/test/paths now accepts failures: true and failures: { dir, replay, key }, the same as testPaths() from @xstate/test. Before, those values threw failureStore.load is not a function.

    import { testPaths } from '@xstate/test/paths';
    
    await testPaths(machine, { events, sut, failures: true });
  • 71b6b6d: testPaths() failure replay fixes:

    • A path that diverges from its planned states is no longer saved by failures, and its error has no fixture. Replaying a fixture does not compare the run with the planned path, so a saved divergence replayed as a pass and was deleted as fixed.
    • With failures: { replay: 'only', key }, saved failures replay even when path planning fails, for example when traversal exceeds limit. Without an explicit key, a planning failure still throws, because the default key depends on the planned paths.