@@ -585,6 +585,15 @@ function isJestTestSkipped (test, hasFocusedTests, testNamePattern) {
585585
586586function getWrappedEnvironment ( BaseEnvironment , jestVersion ) {
587587 const hasConcurrentTestsStartEvent = satisfies ( jestVersion , '>=30.0.0' )
588+ const hasTestsInChildren = satisfies ( jestVersion , '>=26.0.0' )
589+
590+ /**
591+ * @param {object } describeBlock
592+ * @returns {object[]|undefined }
593+ */
594+ function getTestEntries ( describeBlock ) {
595+ return hasTestsInChildren ? describeBlock ?. children : describeBlock ?. tests
596+ }
588597
589598 return class DatadogEnvironment extends BaseEnvironment {
590599 #activeDetachedEfdRetries
@@ -1467,16 +1476,16 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
14671476 const concurrentTestState = registeredConcurrentTestState || this . concurrentTestStates . get ( fn )
14681477 let originalTest
14691478 if ( isEfdRetry && ! efdRetryGates ) {
1470- originalTest = state . currentDescribeBlock ?. children ?. at ( - 1 )
1479+ originalTest = getTestEntries ( state . currentDescribeBlock ) ?. at ( - 1 )
14711480 if ( originalTest ?. fn !== fn ) {
14721481 log . error ( '%s could not retain its original Jest test' , retryType )
14731482 return 0
14741483 }
14751484 }
14761485 let registeredRetryCount = 0
14771486 for ( let retryIndex = 1 ; retryIndex <= retryCount ; retryIndex ++ ) {
1478- const children = state . currentDescribeBlock ?. children
1479- const initialChildCount = children ?. length
1487+ const testEntries = getTestEntries ( state . currentDescribeBlock )
1488+ const initialTestCount = testEntries ?. length
14801489 let retryFn
14811490 if ( concurrentTestState ) {
14821491 const test = concurrentTestState . concurrentTest ??
@@ -1515,7 +1524,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
15151524 }
15161525
15171526 if ( isEfdRetry ) {
1518- const retryTest = children ?. length === initialChildCount + 1 ? children . at ( - 1 ) : undefined
1527+ const retryTest = testEntries ?. length === initialTestCount + 1 ? testEntries . at ( - 1 ) : undefined
15191528 if ( retryTest ?. fn !== retryFn ) {
15201529 log . error ( '%s could not retain its pre-registered Jest retry' , retryType )
15211530 continue
@@ -1545,17 +1554,17 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
15451554 return false
15461555 }
15471556
1548- const children = retryOptions . state . currentDescribeBlock ?. children
1549- const initialChildCount = children ?. length
1557+ const testEntries = getTestEntries ( retryOptions . state . currentDescribeBlock )
1558+ const initialTestCount = testEntries ?. length
15501559 try {
15511560 const registeredRetryCount = this . retryTest ( retryOptions )
15521561 if ( registeredRetryCount === retryOptions . retryCount ) return true
15531562 } catch ( error ) {
15541563 log . error ( '%s could not register retries' , retryOptions . retryType , error )
15551564 }
15561565
1557- if ( children && initialChildCount !== undefined ) {
1558- const retryTests = children . splice ( initialChildCount )
1566+ if ( testEntries && initialTestCount !== undefined ) {
1567+ const retryTests = testEntries . splice ( initialTestCount )
15591568 for ( const retryTest of retryTests ) {
15601569 removedRetryTests . add ( retryTest )
15611570 const retryCtx = this . concurrentTestStates . get ( retryTest . fn ) ?. ctx
@@ -1588,7 +1597,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
15881597 * @returns {number } Retries left to run.
15891598 */
15901599 discardEfdRetries ( testName , executedTest , retryCount = 0 ) {
1591- const siblings = executedTest . parent ?. children
1600+ const siblings = getTestEntries ( executedTest . parent )
15921601 const executedTestIndex = siblings ? siblings . indexOf ( executedTest ) : - 1
15931602 if ( executedTestIndex === - 1 ) return 0
15941603
@@ -1732,7 +1741,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
17321741 if ( ! this . #discardedEfdRetryTests) return
17331742
17341743 for ( const retryTest of this . #discardedEfdRetryTests) {
1735- const siblings = retryTest . parent ?. children
1744+ const siblings = getTestEntries ( retryTest . parent )
17361745 const retryTestIndex = siblings ?. indexOf ( retryTest ) ?? - 1
17371746 if ( retryTestIndex !== - 1 ) {
17381747 siblings . splice ( retryTestIndex , 1 )
@@ -1767,7 +1776,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
17671776 const concurrentTestContexts = this . concurrentTestContexts . get ( testFullName )
17681777 const concurrentTestState = this . concurrentTestStates . get ( event . fn ) ||
17691778 concurrentTestContexts ?. at ( - 1 ) ?. concurrentTestState
1770- const registeredTest = state . currentDescribeBlock ?. children ?. at ( - 1 )
1779+ const registeredTest = getTestEntries ( state . currentDescribeBlock ) ?. at ( - 1 )
17711780 if ( concurrentTestState && registeredTest ?. fn === event . fn ) {
17721781 testContexts . set ( registeredTest , concurrentTestState . ctx )
17731782 }
0 commit comments