@@ -5,9 +5,10 @@ import { createForkActivity } from './fork-activity';
5
5
import { BranchedStep , Definition , Step } from 'sequential-workflow-model' ;
6
6
import { interrupt } from '../results/interrupt-result' ;
7
7
import { branchName } from '../results/branch-name-result' ;
8
+ import { skip } from '../results' ;
8
9
9
10
interface TestGlobalState {
10
- temperature : number ;
11
+ mode : string ;
11
12
message : string ;
12
13
}
13
14
@@ -52,16 +53,22 @@ const activitySet = createActivitySet<TestGlobalState>([
52
53
createForkActivity < BranchedStep , TestGlobalState > ( 'if' , {
53
54
init : ( ) => ( { } ) ,
54
55
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]' ) {
59
57
return interrupt ( ) ;
60
58
}
61
- if ( globalState . temperature > 10 ) {
59
+ if ( globalState . mode === '[fail]' ) {
60
+ throw new Error ( 'TEST_ERROR' ) ;
61
+ }
62
+ if ( globalState . mode === '[true]' ) {
62
63
return branchName ( 'true' ) ;
63
64
}
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' ) ;
65
72
}
66
73
} )
67
74
] ) ;
@@ -77,7 +84,7 @@ function run(definition: Definition, startGlobalState: TestGlobalState) {
77
84
describe ( 'ForkActivity' , ( ) => {
78
85
it ( 'should go by false branch' , done => {
79
86
const startGlobalState : TestGlobalState = {
80
- temperature : 0 ,
87
+ mode : '[false]' ,
81
88
message : ''
82
89
} ;
83
90
@@ -95,7 +102,7 @@ describe('ForkActivity', () => {
95
102
96
103
it ( 'should go by true branch' , done => {
97
104
const startGlobalState : TestGlobalState = {
98
- temperature : 20 ,
105
+ mode : '[true]' ,
99
106
message : ''
100
107
} ;
101
108
@@ -114,7 +121,7 @@ describe('ForkActivity', () => {
114
121
115
122
it ( 'should interrupt' , done => {
116
123
const startGlobalState : TestGlobalState = {
117
- temperature : - 20 ,
124
+ mode : '[interrupt]' ,
118
125
message : ''
119
126
} ;
120
127
@@ -131,9 +138,30 @@ describe('ForkActivity', () => {
131
138
interpreter . start ( ) ;
132
139
} ) ;
133
140
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
+
134
162
it ( 'should fail' , done => {
135
163
const startGlobalState : TestGlobalState = {
136
- temperature : NaN ,
164
+ mode : '[fail]' ,
137
165
message : ''
138
166
} ;
139
167
@@ -143,6 +171,8 @@ describe('ForkActivity', () => {
143
171
const snapshot = interpreter . getSnapshot ( ) ;
144
172
145
173
expect ( snapshot . isFailed ( ) ) . toBe ( true ) ;
174
+ expect ( snapshot . isInterrupted ( ) ) . toBe ( false ) ;
175
+ expect ( snapshot . isFinished ( ) ) . toBe ( false ) ;
146
176
expect ( snapshot . unhandledError ?. message ) . toBe ( 'TEST_ERROR' ) ;
147
177
expect ( snapshot . unhandledError ?. stepId ) . toBe ( '0x002' ) ;
148
178
expect ( snapshot . globalState . message ) . toBe ( '(start)' ) ;
0 commit comments