@@ -33,10 +33,11 @@ const {
3333 getTestOptimizationRequestResults,
3434} = require ( '../../dd-trace/src/plugins/util/test' )
3535const {
36- SEED_SUFFIX_RE ,
3736 getFormattedJestTestParameters,
3837 getJestTestName,
38+ getRawJestTestName,
3939 getJestSuitesToRun,
40+ removeSeedSuffixFromTestName,
4041} = require ( '../../datadog-plugin-jest/src/util' )
4142const { addHook, channel } = require ( './helpers/instrument' )
4243
@@ -130,8 +131,6 @@ const efdSlowAbortedTests = new Set()
130131const efdNewTestCandidates = new Set ( )
131132// Tests that are genuinely new (not in known tests list).
132133const newTests = new Set ( )
133- const testSuiteAbsolutePathsWithFastCheck = new Set ( )
134- const testSuiteFastCheckUsage = new Map ( )
135134const testSuiteJestObjects = new Map ( )
136135const wrappedJestGlobals = new WeakSet ( )
137136const wrappedJestObjects = new WeakSet ( )
@@ -293,9 +292,7 @@ function getAttemptToFixExecutionsFromJestResults (result) {
293292 if ( ! testManagementTestsForSuite ) continue
294293
295294 for ( const { fullName, status } of testResults ) {
296- const testName = testSuiteAbsolutePathsWithFastCheck . has ( testFilePath )
297- ? fullName . replace ( SEED_SUFFIX_RE , '' )
298- : fullName
295+ const testName = removeSeedSuffixFromTestName ( fullName )
299296 const testStatus = getTestStatusFromJestResult ( status )
300297 if ( ! testStatus ) continue
301298
@@ -542,14 +539,11 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
542539 }
543540 }
544541
545- getShouldStripSeedFromTestName ( ) {
546- return doesTestSuiteUseFastCheck ( this . testSuiteAbsolutePath )
547- }
548-
549542 // At the `add_test` event we don't have the test object yet, so we can't use it
550543 getTestNameFromAddTestEvent ( event , state ) {
551- const describeSuffix = getJestTestName ( state . currentDescribeBlock , this . getShouldStripSeedFromTestName ( ) )
552- return describeSuffix ? `${ describeSuffix } ${ event . testName } ` : event . testName
544+ const describeSuffix = getRawJestTestName ( state . currentDescribeBlock )
545+ const testName = describeSuffix ? `${ describeSuffix } ${ event . testName } ` : event . testName
546+ return removeSeedSuffixFromTestName ( testName )
553547 }
554548
555549 async handleTestEvent ( event , state ) {
@@ -571,7 +565,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
571565 } )
572566 }
573567 if ( event . name === 'test_start' ) {
574- const testName = getJestTestName ( event . test , this . getShouldStripSeedFromTestName ( ) )
568+ const testName = getJestTestName ( event . test )
575569 if ( testsToBeRetried . has ( testName ) ) {
576570 // This is needed because we're retrying tests with the same name
577571 this . resetSnapshotState ( )
@@ -775,7 +769,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
775769 let attemptToFixFailed = false
776770 let failedAllTests = false
777771 let isAttemptToFix = false
778- const testName = getJestTestName ( event . test , this . getShouldStripSeedFromTestName ( ) )
772+ const testName = getJestTestName ( event . test )
779773 if ( this . isTestManagementTestsEnabled ) {
780774 isAttemptToFix = this . testManagementTestsForThisSuite ?. attemptToFix ?. includes ( testName )
781775 if ( isAttemptToFix ) {
@@ -955,7 +949,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
955949 // so Jest doesn't see the failure (prevents --bail from stopping the run).
956950 const ctx = testContexts . get ( test )
957951 if ( ctx ?. isQuarantined && ! ctx . isAttemptToFix ) {
958- const testName = getJestTestName ( test , this . getShouldStripSeedFromTestName ( ) )
952+ const testName = getJestTestName ( test )
959953 quarantinedFailingTests . add ( `${ ctx . suite } › ${ testName } ` )
960954 } else {
961955 test . errors = errors
@@ -979,7 +973,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
979973 testsToBeRetried . clear ( )
980974 }
981975 if ( event . name === 'test_skip' || event . name === 'test_todo' ) {
982- const testName = getJestTestName ( event . test , this . getShouldStripSeedFromTestName ( ) )
976+ const testName = getJestTestName ( event . test )
983977 testSkippedCh . publish ( {
984978 test : {
985979 name : testName ,
@@ -1383,9 +1377,7 @@ function getCliWrapper (isNewJestVersion) {
13831377 for ( const { testResults, testFilePath } of result . results . testResults ) {
13841378 const suite = getTestSuitePath ( testFilePath , result . globalConfig . rootDir )
13851379 for ( const { fullName } of testResults ) {
1386- const name = testSuiteAbsolutePathsWithFastCheck . has ( testFilePath )
1387- ? fullName . replace ( SEED_SUFFIX_RE , '' )
1388- : fullName
1380+ const name = removeSeedSuffixFromTestName ( fullName )
13891381 fullNameToSuite . set ( name , suite )
13901382 }
13911383 }
@@ -1424,10 +1416,8 @@ function getCliWrapper (isNewJestVersion) {
14241416 . testResults . flatMap ( ( { testResults, testFilePath : testSuiteAbsolutePath } ) => (
14251417 testResults . map ( ( { fullName : testName , status } ) => (
14261418 {
1427- // Strip @fast -check/jest seed suffix so the name matches what was reported via TEST_NAME
1428- testName : testSuiteAbsolutePathsWithFastCheck . has ( testSuiteAbsolutePath )
1429- ? testName . replace ( SEED_SUFFIX_RE , '' )
1430- : testName ,
1419+ // Strip seed suffix so the name matches what was reported via TEST_NAME.
1420+ testName : removeSeedSuffixFromTestName ( testName ) ,
14311421 testSuiteAbsolutePath,
14321422 status,
14331423 }
@@ -1626,7 +1616,6 @@ function publishTestSuiteFinish (payload, waitForFinish) {
16261616
16271617function cleanupTestSuiteState ( testSuiteAbsolutePath ) {
16281618 testSuiteMockedFiles . delete ( testSuiteAbsolutePath )
1629- testSuiteFastCheckUsage . delete ( testSuiteAbsolutePath )
16301619 testSuiteJestObjects . delete ( testSuiteAbsolutePath )
16311620}
16321621
@@ -2080,38 +2069,6 @@ function wrapJestGlobalsForRuntime (runtime) {
20802069 } )
20812070}
20822071
2083- function recordFastCheckUsage ( runtime , from , moduleName ) {
2084- if ( moduleName !== '@fast-check/jest' ) return
2085-
2086- if ( from ) {
2087- testSuiteAbsolutePathsWithFastCheck . add ( from )
2088- testSuiteFastCheckUsage . set ( from , true )
2089- }
2090- if ( runtime ?. _testPath ) {
2091- testSuiteAbsolutePathsWithFastCheck . add ( runtime . _testPath )
2092- testSuiteFastCheckUsage . set ( runtime . _testPath , true )
2093- }
2094- }
2095-
2096- function doesTestSuiteUseFastCheck ( testSuiteAbsolutePath ) {
2097- if ( ! testSuiteAbsolutePath ) return false
2098- if ( testSuiteFastCheckUsage . has ( testSuiteAbsolutePath ) ) {
2099- return testSuiteFastCheckUsage . get ( testSuiteAbsolutePath )
2100- }
2101-
2102- try {
2103- const usesFastCheck = readFileSync ( testSuiteAbsolutePath , 'utf8' ) . includes ( '@fast-check/jest' )
2104- testSuiteFastCheckUsage . set ( testSuiteAbsolutePath , usesFastCheck )
2105- if ( usesFastCheck ) {
2106- testSuiteAbsolutePathsWithFastCheck . add ( testSuiteAbsolutePath )
2107- }
2108- return usesFastCheck
2109- } catch {
2110- testSuiteFastCheckUsage . set ( testSuiteAbsolutePath , false )
2111- return false
2112- }
2113- }
2114-
21152072function getLastLoggedReferenceError ( runtime ) {
21162073 const loggedReferenceErrors = runtime ?. loggedReferenceErrors
21172074 if ( ! loggedReferenceErrors ?. size ) return
@@ -2220,8 +2177,6 @@ addHook({
22202177 // To bypass jest's own require engine
22212178 return requireOutsideJestRequireEngine ( this , moduleName )
22222179 }
2223- // This means that `@fast-check/jest` is used in the test file.
2224- recordFastCheckUsage ( this , from , moduleName )
22252180 let returnedValue
22262181 try {
22272182 returnedValue = requireModuleOrMock . apply ( this , arguments )
0 commit comments