@@ -252,19 +252,23 @@ export async function run(workflow: Workflow, options?: WorkflowOptions): Promis
252252 const concurrency = options ?. concurrency || workflow . config ?. concurrency || Object . keys ( workflow . tests ) . length
253253 const limit = pLimit ( concurrency <= 0 ? 1 : concurrency )
254254
255- let testResults : TestResult [ ] = [ ]
255+ const testResults : TestResult [ ] = [ ]
256+ const captures : CapturesStorage = { }
256257
258+ // Run `before` section
257259 if ( workflow . before ) {
258- const beforeResult = await runTest ( 'before' , workflow . before , schemaValidator , options , workflow . config , env )
260+ const beforeResult = await runTest ( 'before' , workflow . before , schemaValidator , options , workflow . config , env , captures )
259261 testResults . push ( beforeResult )
260262 }
261263
264+ // Run `tests` section
262265 const input : Promise < TestResult > [ ] = [ ]
263- Object . entries ( workflow . tests ) . map ( ( [ id , test ] ) => input . push ( limit ( ( ) => runTest ( id , test , schemaValidator , options , workflow . config , env ) ) ) )
266+ Object . entries ( workflow . tests ) . map ( ( [ id , test ] ) => input . push ( limit ( ( ) => runTest ( id , test , schemaValidator , options , workflow . config , env , { ... captures } ) ) ) )
264267 testResults . push ( ...await Promise . all ( input ) )
265268
269+ // Run `after` section
266270 if ( workflow . after ) {
267- const afterResult = await runTest ( 'after' , workflow . after , schemaValidator , options , workflow . config , env )
271+ const afterResult = await runTest ( 'after' , workflow . after , schemaValidator , options , workflow . config , env , captures )
268272 testResults . push ( afterResult )
269273 }
270274
@@ -286,7 +290,7 @@ export async function run(workflow: Workflow, options?: WorkflowOptions): Promis
286290 return workflowResult
287291}
288292
289- async function runTest ( id : string , test : Test , schemaValidator : Ajv , options ?: WorkflowOptions , config ?: WorkflowConfig , env ?: object ) : Promise < TestResult > {
293+ async function runTest ( id : string , test : Test , schemaValidator : Ajv , options ?: WorkflowOptions , config ?: WorkflowConfig , env ?: object , capturesStorage ?: CapturesStorage ) : Promise < TestResult > {
290294 const testResult : TestResult = {
291295 id,
292296 name : test . name ,
@@ -299,7 +303,7 @@ async function runTest(id: string, test: Test, schemaValidator: Ajv, options?: W
299303 bytesReceived : 0
300304 }
301305
302- const captures : CapturesStorage = { }
306+ const captures : CapturesStorage = capturesStorage ?? { }
303307 const cookies = new CookieJar ( )
304308 let previous : StepResult | undefined
305309 let testData : object = { }
0 commit comments