1- import { randomUUID } from "crypto" ;
21import { rm } from "fs/promises" ;
32import { resolve } from "path" ;
43import { fetch } from "undici" ;
5- import { afterAll , beforeAll , describe , it , test , vi } from "vitest" ;
4+ import { afterAll , beforeAll , describe , it , vi } from "vitest" ;
65import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived" ;
76
87describe ( "Workflows" , ( ) => {
@@ -27,13 +26,11 @@ describe("Workflows", () => {
2726 await stop ?.( ) ;
2827 } ) ;
2928
30- async function fetchJson ( url : string , body ?: unknown , method ?: string ) {
29+ async function fetchJson ( url : string ) {
3130 const response = await fetch ( url , {
3231 headers : {
3332 "MF-Disable-Pretty-Error" : "1" ,
3433 } ,
35- method : method ?? "GET" ,
36- body : body !== undefined ? JSON . stringify ( body ) : undefined ,
3734 } ) ;
3835 const text = await response . text ( ) ;
3936
@@ -95,150 +92,4 @@ describe("Workflows", () => {
9592 ) ,
9693 ] ) ;
9794 } ) ;
98-
99- describe ( "instance lifecycle methods (workflow3)" , ( ) => {
100- test ( "pause and resume a workflow" , async ( { expect } ) => {
101- const id = randomUUID ( ) ;
102-
103- await fetchJson ( `http://${ ip } :${ port } /create?workflowName=3&id=${ id } ` ) ;
104-
105- await vi . waitFor (
106- async ( ) => {
107- const result = ( await fetchJson (
108- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
109- ) ) as {
110- status : {
111- __LOCAL_DEV_STEP_OUTPUTS : { output : string } [ ] ;
112- } ;
113- } ;
114- expect ( result . status . __LOCAL_DEV_STEP_OUTPUTS ) . toContainEqual ( {
115- output : "First step result" ,
116- } ) ;
117- } ,
118- { timeout : 5000 }
119- ) ;
120-
121- // Pause the instance
122- await fetchJson ( `http://${ ip } :${ port } /pause?workflowName=3&id=${ id } ` ) ;
123-
124- await vi . waitFor (
125- async ( ) => {
126- const result = ( await fetchJson (
127- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
128- ) ) as { status : { status : string } } ;
129- expect ( result . status . status ) . toBe ( "paused" ) ;
130- } ,
131- { timeout : 5000 }
132- ) ;
133-
134- // Resume the instance
135- await fetchJson ( `http://${ ip } :${ port } /resume?workflowName=3&id=${ id } ` ) ;
136-
137- await fetchJson (
138- `http://${ ip } :${ port } /sendEvent?workflowName=3&id=${ id } ` ,
139- { done : true } ,
140- "POST"
141- ) ;
142-
143- await vi . waitFor (
144- async ( ) => {
145- const result = ( await fetchJson (
146- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
147- ) ) as { status : { status : string ; output : string } } ;
148- expect ( result . status . status ) . toBe ( "complete" ) ;
149- expect ( result . status . output ) . toBe ( "i'm workflow3" ) ;
150- } ,
151- { timeout : 5000 }
152- ) ;
153- } ) ;
154-
155- test ( "terminate a running workflow" , async ( { expect } ) => {
156- const id = randomUUID ( ) ;
157-
158- await fetchJson ( `http://${ ip } :${ port } /create?workflowName=3&id=${ id } ` ) ;
159-
160- await vi . waitFor (
161- async ( ) => {
162- const result = ( await fetchJson (
163- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
164- ) ) as {
165- status : {
166- __LOCAL_DEV_STEP_OUTPUTS : { output : string } [ ] ;
167- } ;
168- } ;
169- expect ( result . status . __LOCAL_DEV_STEP_OUTPUTS ) . toContainEqual ( {
170- output : "First step result" ,
171- } ) ;
172- } ,
173- { timeout : 5000 }
174- ) ;
175-
176- // Terminate
177- await fetchJson ( `http://${ ip } :${ port } /terminate?workflowName=3&id=${ id } ` ) ;
178-
179- await vi . waitFor (
180- async ( ) => {
181- const result = ( await fetchJson (
182- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
183- ) ) as { status : { status : string } } ;
184- expect ( result . status . status ) . toBe ( "terminated" ) ;
185- } ,
186- { timeout : 5000 }
187- ) ;
188- } ) ;
189-
190- test ( "restart a running workflow" , async ( { expect } ) => {
191- const id = randomUUID ( ) ;
192-
193- await fetchJson ( `http://${ ip } :${ port } /create?workflowName=3&id=${ id } ` ) ;
194-
195- await vi . waitFor (
196- async ( ) => {
197- const result = ( await fetchJson (
198- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
199- ) ) as {
200- status : {
201- __LOCAL_DEV_STEP_OUTPUTS : { output : string } [ ] ;
202- } ;
203- } ;
204- expect ( result . status . __LOCAL_DEV_STEP_OUTPUTS ) . toContainEqual ( {
205- output : "First step result" ,
206- } ) ;
207- } ,
208- { timeout : 5000 }
209- ) ;
210-
211- // Restart the instance
212- await fetchJson ( `http://${ ip } :${ port } /restart?workflowName=3&id=${ id } ` ) ;
213-
214- // After restart, wait for it to be running again
215- await vi . waitFor (
216- async ( ) => {
217- const result = ( await fetchJson (
218- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
219- ) ) as { status : { status : string } } ;
220- expect ( result . status . status ) . toBe ( "running" ) ;
221- } ,
222- { timeout : 5000 }
223- ) ;
224-
225- // Send event to complete the restarted workflow
226- await fetchJson (
227- `http://${ ip } :${ port } /sendEvent?workflowName=3&id=${ id } ` ,
228- { done : true } ,
229- "POST"
230- ) ;
231-
232- await vi . waitFor (
233- async ( ) => {
234- const result = ( await fetchJson (
235- `http://${ ip } :${ port } /status?workflowName=3&id=${ id } `
236- ) ) as { status : { status : string ; output : string } } ;
237- expect ( result . status . status ) . toBe ( "complete" ) ;
238- expect ( result . status . output ) . toBe ( "i'm workflow3" ) ;
239- } ,
240- { timeout : 5000 }
241- ) ;
242- } ) ;
243- } ) ;
24495} ) ;
0 commit comments