1+ import { beforeEach } from "node:test" ;
12import { env , introspectWorkflow , SELF } from "cloudflare:test" ;
23import { describe , expect , it , vi } from "vitest" ;
34
45const STATUS_COMPLETE = "complete" ;
56
67describe ( "Test Workflow" , ( ) => {
78 it ( "should be able to trigger a workflow" , async ( ) => {
9+ // With `using` to ensure cleanup:
10+ await using introspector = await introspectWorkflow ( env . TEST_WORKFLOW ) ;
811 const res = await SELF . fetch ( "https://mock-worker.local" ) ;
912
1013 expect ( res . status ) . toBe ( 200 ) ;
1114 } ) ;
1215
1316 it ( "workflow should reach the end and be successful" , async ( ) => {
17+ // With `using` to ensure cleanup:
18+ await using introspector = await introspectWorkflow ( env . TEST_WORKFLOW ) ;
1419 const res = await SELF . fetch ( "https://mock-worker.local" ) ;
1520
1621 const json = await res . json < { id : string } > ( ) ;
@@ -68,7 +73,8 @@ describe("Test long Workflow", () => {
6873 // CLEANUP: done by Symbol.asyncDispose
6974 } ) ;
7075
71- it ( "workflow batch should be able to introspect and reach the end and be successful" , async ( ) => {
76+ it ( "workflow batch should be able to introspect and reach the end and be successful (explicit cleanup)" , async ( ) => {
77+ // CONFIG:
7278 let introspector = await introspectWorkflow ( env . TEST_LONG_WORKFLOW ) ;
7379 introspector . modifyAll ( async ( m ) => {
7480 await m . disableSleeps ( ) ;
@@ -91,6 +97,6 @@ describe("Test long Workflow", () => {
9197 // CLEANUP:
9298 // Workflow introspector should be cleaned at the end of/after each test, if no `using` keyword is used for the introspector
9399 // Cleans up all intercepted instances
94- introspector . cleanUp ( ) ;
100+ await introspector . cleanUp ( ) ;
95101 } ) ;
96102} ) ;
0 commit comments