11import { rm } from "fs/promises" ;
22import { resolve } from "path" ;
33import { fetch } from "undici" ;
4- import { afterAll , beforeAll , describe , it , vi } from "vitest" ;
4+ import { afterAll , beforeAll , describe , it , test , vi } from "vitest" ;
55import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived" ;
66
77describe ( "Workflows" , ( ) => {
@@ -26,11 +26,13 @@ describe("Workflows", () => {
2626 await stop ?.( ) ;
2727 } ) ;
2828
29- async function fetchJson ( url : string ) {
29+ async function fetchJson ( url : string , body ?: unknown , method ?: string ) {
3030 const response = await fetch ( url , {
3131 headers : {
3232 "MF-Disable-Pretty-Error" : "1" ,
3333 } ,
34+ method : method ?? "GET" ,
35+ body : body !== undefined ? JSON . stringify ( body ) : undefined ,
3436 } ) ;
3537 const text = await response . text ( ) ;
3638
@@ -98,4 +100,84 @@ describe("Workflows", () => {
98100 name : "Error" ,
99101 } ) ;
100102 } ) ;
103+
104+ test ( "batchCreate should create multiple instances and run them seperatly" , async ( {
105+ expect,
106+ } ) => {
107+ await expect ( fetchJson ( `http://${ ip } :${ port } /createBatch` ) ) . resolves
108+ . toMatchInlineSnapshot ( `
109+ [
110+ "batch-1",
111+ "batch-2",
112+ ]
113+ ` ) ;
114+
115+ await Promise . all ( [
116+ vi . waitFor (
117+ async ( ) => {
118+ await expect (
119+ fetchJson ( `http://${ ip } :${ port } /status?workflowName=batch-1` )
120+ ) . resolves . toStrictEqual ( {
121+ status : "complete" ,
122+ __LOCAL_DEV_STEP_OUTPUTS : [
123+ { output : "First step result" } ,
124+ { output : "Second step result" } ,
125+ ] ,
126+ output : "1" ,
127+ } ) ;
128+ } ,
129+ { timeout : 5000 }
130+ ) ,
131+ vi . waitFor (
132+ async ( ) => {
133+ await expect (
134+ fetchJson ( `http://${ ip } :${ port } /status?workflowName=batch-2` )
135+ ) . resolves . toStrictEqual ( {
136+ status : "complete" ,
137+ __LOCAL_DEV_STEP_OUTPUTS : [
138+ { output : "First step result" } ,
139+ { output : "Second step result" } ,
140+ ] ,
141+ output : "2" ,
142+ } ) ;
143+ } ,
144+ { timeout : 5000 }
145+ ) ,
146+ ] ) ;
147+ } ) ;
148+
149+ test ( "waitForEvent should work" , async ( { expect } ) => {
150+ await fetchJson ( `http://${ ip } :${ port } /createDemo2?workflowName=something` ) ;
151+
152+ await fetchJson (
153+ `http://${ ip } :${ port } /sendEvent?workflowName=something` ,
154+ { event : true } ,
155+ "POST"
156+ ) ;
157+
158+ await vi . waitFor (
159+ async ( ) => {
160+ await expect (
161+ fetchJson ( `http://${ ip } :${ port } /get2?workflowName=something` )
162+ ) . resolves . toMatchInlineSnapshot ( `
163+ {
164+ "__LOCAL_DEV_STEP_OUTPUTS": [
165+ {
166+ "output": "First step result",
167+ },
168+ {
169+ "event": true,
170+ },
171+ {
172+ "output": "Second step result",
173+ },
174+ ],
175+ "output": {},
176+ "status": "complete",
177+ }
178+ ` ) ;
179+ } ,
180+ { timeout : 5000 }
181+ ) ;
182+ } ) ;
101183} ) ;
0 commit comments