( machine: AnyStateMachine, test: SCIONTest )
| 385 | } |
| 386 | |
| 387 | async 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 | |
| 436 | describe('scxml', () => { |
| 437 | const onlyTests: string[] = [ |
no test coverage detected
searching dependent graphs…