@@ -69,7 +69,7 @@ export function logFeedback(
69
69
exampleId : context . currentExample . id ,
70
70
feedback : feedback ,
71
71
context,
72
- runTree : trackingEnabled ( context ) ? getCurrentRunTree ( ) : undefined ,
72
+ runTree : context . testRootRunTree ,
73
73
client : context . client ,
74
74
} ) ;
75
75
}
@@ -491,59 +491,72 @@ export function generateWrapperFromJestlikeMethods(
491
491
} ;
492
492
let exampleId : string ;
493
493
const runTestFn = async ( ) => {
494
- const testContext =
495
- testWrapperAsyncLocalStorageInstance . getStore ( ) ;
494
+ let testContext = testWrapperAsyncLocalStorageInstance . getStore ( ) ;
496
495
if ( testContext === undefined ) {
497
496
throw new Error (
498
497
"Could not identify test context. Please contact us for help."
499
498
) ;
500
499
}
501
- try {
502
- const res = await testFn ( {
503
- ...rest ,
504
- inputs : testInput ,
505
- referenceOutputs : testOutput ,
506
- } ) ;
507
- _logTestFeedback ( {
508
- exampleId,
509
- feedback : { key : "pass" , score : true } ,
510
- context : testContext ,
511
- runTree : trackingEnabled ( testContext )
500
+ return testWrapperAsyncLocalStorageInstance . run (
501
+ {
502
+ ...testContext ,
503
+ testRootRunTree : trackingEnabled ( testContext )
512
504
? getCurrentRunTree ( )
513
505
: undefined ,
514
- client : testContext . client ,
515
- } ) ;
516
- if ( res != null ) {
517
- if ( loggedOutput ! == undefined ) {
518
- console . warn (
519
- `[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`
506
+ } ,
507
+ async ( ) => {
508
+ testContext = testWrapperAsyncLocalStorageInstance . getStore ( ) ;
509
+ if ( testContext = == undefined ) {
510
+ throw new Error (
511
+ "Could not identify test context after setting test root run tree. Please contact us for help."
520
512
) ;
521
513
}
522
- loggedOutput =
523
- typeof res === "object"
524
- ? ( res as Record < string , unknown > )
525
- : { result : res } ;
514
+ try {
515
+ const res = await testFn ( {
516
+ ...rest ,
517
+ inputs : testInput ,
518
+ referenceOutputs : testOutput ,
519
+ } ) ;
520
+ _logTestFeedback ( {
521
+ exampleId,
522
+ feedback : { key : "pass" , score : true } ,
523
+ context : testContext ,
524
+ runTree : testContext . testRootRunTree ,
525
+ client : testContext . client ,
526
+ } ) ;
527
+ if ( res != null ) {
528
+ if ( loggedOutput !== undefined ) {
529
+ console . warn (
530
+ `[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`
531
+ ) ;
532
+ }
533
+ loggedOutput =
534
+ typeof res === "object"
535
+ ? ( res as Record < string , unknown > )
536
+ : { result : res } ;
537
+ }
538
+ return loggedOutput ;
539
+ } catch ( e : any ) {
540
+ _logTestFeedback ( {
541
+ exampleId,
542
+ feedback : { key : "pass" , score : false } ,
543
+ context : testContext ,
544
+ runTree : testContext . testRootRunTree ,
545
+ client : testContext . client ,
546
+ } ) ;
547
+ const rawError = e ;
548
+ const strippedErrorMessage = e . message . replace (
549
+ STRIP_ANSI_REGEX ,
550
+ ""
551
+ ) ;
552
+ const langsmithFriendlyError = new Error (
553
+ strippedErrorMessage
554
+ ) ;
555
+ ( langsmithFriendlyError as any ) . rawJestError = rawError ;
556
+ throw langsmithFriendlyError ;
557
+ }
526
558
}
527
- return loggedOutput ;
528
- } catch ( e : any ) {
529
- _logTestFeedback ( {
530
- exampleId,
531
- feedback : { key : "pass" , score : false } ,
532
- context : testContext ,
533
- runTree : trackingEnabled ( testContext )
534
- ? getCurrentRunTree ( )
535
- : undefined ,
536
- client : testContext . client ,
537
- } ) ;
538
- const rawError = e ;
539
- const strippedErrorMessage = e . message . replace (
540
- STRIP_ANSI_REGEX ,
541
- ""
542
- ) ;
543
- const langsmithFriendlyError = new Error ( strippedErrorMessage ) ;
544
- ( langsmithFriendlyError as any ) . rawJestError = rawError ;
545
- throw langsmithFriendlyError ;
546
- }
559
+ ) ;
547
560
} ;
548
561
try {
549
562
if ( trackingEnabled ( context ) ) {
0 commit comments