@@ -5,9 +5,10 @@ import { createForkActivity } from './fork-activity';
55import { BranchedStep , Definition , Step } from 'sequential-workflow-model' ;
66import { interrupt } from '../results/interrupt-result' ;
77import { branchName } from '../results/branch-name-result' ;
8+ import { skip } from '../results' ;
89
910interface TestGlobalState {
10- temperature : number ;
11+ mode : string ;
1112 message : string ;
1213}
1314
@@ -52,16 +53,22 @@ const activitySet = createActivitySet<TestGlobalState>([
5253 createForkActivity < BranchedStep , TestGlobalState > ( 'if' , {
5354 init : ( ) => ( { } ) ,
5455 handler : async ( _ , globalState ) => {
55- if ( isNaN ( globalState . temperature ) ) {
56- throw new Error ( 'TEST_ERROR' ) ;
57- }
58- if ( globalState . temperature < 0 ) {
56+ if ( globalState . mode === '[interrupt]' ) {
5957 return interrupt ( ) ;
6058 }
61- if ( globalState . temperature > 10 ) {
59+ if ( globalState . mode === '[fail]' ) {
60+ throw new Error ( 'TEST_ERROR' ) ;
61+ }
62+ if ( globalState . mode === '[true]' ) {
6263 return branchName ( 'true' ) ;
6364 }
64- return branchName ( 'false' ) ;
65+ if ( globalState . mode === '[false]' ) {
66+ return branchName ( 'false' ) ;
67+ }
68+ if ( globalState . mode === '[skip]' ) {
69+ return skip ( ) ;
70+ }
71+ throw new Error ( 'Unknown mode' ) ;
6572 }
6673 } )
6774] ) ;
@@ -77,7 +84,7 @@ function run(definition: Definition, startGlobalState: TestGlobalState) {
7784describe ( 'ForkActivity' , ( ) => {
7885 it ( 'should go by false branch' , done => {
7986 const startGlobalState : TestGlobalState = {
80- temperature : 0 ,
87+ mode : '[false]' ,
8188 message : ''
8289 } ;
8390
@@ -95,7 +102,7 @@ describe('ForkActivity', () => {
95102
96103 it ( 'should go by true branch' , done => {
97104 const startGlobalState : TestGlobalState = {
98- temperature : 20 ,
105+ mode : '[true]' ,
99106 message : ''
100107 } ;
101108
@@ -114,7 +121,7 @@ describe('ForkActivity', () => {
114121
115122 it ( 'should interrupt' , done => {
116123 const startGlobalState : TestGlobalState = {
117- temperature : - 20 ,
124+ mode : '[interrupt]' ,
118125 message : ''
119126 } ;
120127
@@ -131,9 +138,30 @@ describe('ForkActivity', () => {
131138 interpreter . start ( ) ;
132139 } ) ;
133140
141+ it ( 'should skip' , done => {
142+ const startGlobalState : TestGlobalState = {
143+ mode : '[skip]' ,
144+ message : ''
145+ } ;
146+
147+ const interpreter = run ( definition , startGlobalState ) ;
148+
149+ interpreter . onDone ( ( ) => {
150+ const snapshot = interpreter . getSnapshot ( ) ;
151+
152+ expect ( snapshot . isFinished ( ) ) . toBe ( true ) ;
153+ expect ( snapshot . isInterrupted ( ) ) . toBe ( false ) ;
154+ expect ( snapshot . isFailed ( ) ) . toBe ( false ) ;
155+ expect ( snapshot . globalState . message ) . toBe ( '(start)(end)' ) ;
156+
157+ done ( ) ;
158+ } ) ;
159+ interpreter . start ( ) ;
160+ } ) ;
161+
134162 it ( 'should fail' , done => {
135163 const startGlobalState : TestGlobalState = {
136- temperature : NaN ,
164+ mode : '[fail]' ,
137165 message : ''
138166 } ;
139167
@@ -143,6 +171,8 @@ describe('ForkActivity', () => {
143171 const snapshot = interpreter . getSnapshot ( ) ;
144172
145173 expect ( snapshot . isFailed ( ) ) . toBe ( true ) ;
174+ expect ( snapshot . isInterrupted ( ) ) . toBe ( false ) ;
175+ expect ( snapshot . isFinished ( ) ) . toBe ( false ) ;
146176 expect ( snapshot . unhandledError ?. message ) . toBe ( 'TEST_ERROR' ) ;
147177 expect ( snapshot . unhandledError ?. stepId ) . toBe ( '0x002' ) ;
148178 expect ( snapshot . globalState . message ) . toBe ( '(start)' ) ;
0 commit comments