MCPcopy
hub / github.com/statelyai/xstate / runTestToCompletion

Function runTestToCompletion

packages/core/test/scxml.test.ts:387–434  ·  view source on GitHub ↗
(
  machine: AnyStateMachine,
  test: SCIONTest
)

Source from the content-addressed store, hash-verified

385}
386
387async function runTestToCompletion(
388 machine: AnyStateMachine,
389 test: SCIONTest
390): Promise<void> {
391 if (!test.events.length && test.initialConfiguration[0] === 'pass') {
392 await runW3TestToCompletion(machine);
393 return;
394 }
395
396 let done = false;
397 const service = createActor(machine, {
398 clock: new SimulatedClock()
399 });
400
401 let nextState: AnyMachineSnapshot = service.getSnapshot();
402 let prevState: AnyMachineSnapshot;
403 service.subscribe((state) => {
404 prevState = nextState;
405 nextState = state;
406 });
407 service.subscribe({
408 complete: () => {
409 if (nextState.value === 'fail') {
410 throw new Error(
411 `Reached "fail" state from state ${JSON.stringify(prevState?.value)}`
412 );
413 }
414 done = true;
415 }
416 });
417 service.start();
418
419 test.events.forEach(({ event, nextConfiguration, after }) => {
420 if (done) {
421 return;
422 }
423 if (after) {
424 (service.clock as SimulatedClock).increment(after);
425 }
426 service.send({ type: event.name });
427
428 const stateIds = getStateNodes(machine.root, nextState.value).map(
429 (stateNode) => stateNode.id
430 );
431
432 expect(stateIds).toContain(sanitizeStateId(nextConfiguration[0]));
433 });
434}
435
436describe('scxml', () => {
437 const onlyTests: string[] = [

Callers 1

scxml.test.tsFile · 0.85

Calls 9

createActorFunction · 0.90
getStateNodesFunction · 0.90
sanitizeStateIdFunction · 0.90
runW3TestToCompletionFunction · 0.85
getSnapshotMethod · 0.80
sendMethod · 0.80
subscribeMethod · 0.65
startMethod · 0.65
incrementMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…