@@ -21,6 +21,7 @@ const {
2121 getTestSuitePath,
2222 getRelativeCoverageFiles,
2323 CUCUMBER_WORKER_TRACE_PAYLOAD_CODE ,
24+ CUCUMBER_WORKER_TELEMETRY_PAYLOAD_CODE ,
2425 getIsFaultyEarlyFlakeDetection,
2526 applySkippedCoverageToCoverage,
2627 getTestCoverageLinesPercentage,
@@ -62,6 +63,7 @@ const modifiedFilesCh = channel('ci:cucumber:modified-files')
6263const isModifiedCh = channel ( 'ci:cucumber:is-modified-test' )
6364
6465const workerReportTraceCh = channel ( 'ci:cucumber:worker-report:trace' )
66+ const workerReportTelemetryCh = channel ( 'ci:cucumber:worker-report:telemetry' )
6567
6668const itrSkippedSuitesCh = channel ( 'ci:cucumber:itr:skipped-suites' )
6769
@@ -303,6 +305,10 @@ function handleDdWorkerMessage (message) {
303305 workerReportTraceCh . publish ( payload )
304306 return true
305307 }
308+ if ( messageCode === CUCUMBER_WORKER_TELEMETRY_PAYLOAD_CODE ) {
309+ workerReportTelemetryCh . publish ( payload )
310+ return true
311+ }
306312 }
307313
308314 if ( message ?. [ DD_EFD_RETRY_COUNT_MESSAGE ] ) {
@@ -351,8 +357,10 @@ function maybeStartParallelSuite (pickle) {
351357 } )
352358}
353359
354- function handleParallelTestCaseFinished ( pickle , worstTestStepResult ) {
355- const { status } = getStatusFromResultLatest ( worstTestStepResult )
360+ function handleParallelTestCaseFinished ( pickle , worstTestStepResult , usesNumericStatus = false ) {
361+ const { status } = usesNumericStatus
362+ ? getStatusFromResult ( worstTestStepResult )
363+ : getStatusFromResultLatest ( worstTestStepResult )
356364 let isNew = false
357365
358366 if ( isKnownTestsEnabled ) {
@@ -1488,7 +1496,7 @@ function patchCucumberWorkerRunTestCase (runtimeExecutorPackage, isWorker) {
14881496 )
14891497}
14901498
1491- function getWrappedParseWorkerMessage ( parseWorkerMessageFunction , isNewVersion ) {
1499+ function getWrappedParseWorkerMessage ( parseWorkerMessageFunction , isNewVersion , usesNumericStatus = false ) {
14921500 return function ( worker , message ) {
14931501 if ( ! testSuiteFinishCh . hasSubscribers ) {
14941502 return parseWorkerMessageFunction . apply ( this , arguments )
@@ -1539,13 +1547,31 @@ function getWrappedParseWorkerMessage (parseWorkerMessageFunction, isNewVersion)
15391547 pickle = testCase . pickle
15401548 }
15411549
1542- handleParallelTestCaseFinished ( pickle , worstTestStepResult )
1550+ handleParallelTestCaseFinished ( pickle , worstTestStepResult , usesNumericStatus )
15431551 }
15441552
15451553 return parseWorkerResponse
15461554 }
15471555}
15481556
1557+ /**
1558+ * Adapts Cucumber 7's callback-based parallel coordinator to the Promise contract used by getWrappedStart.
1559+ *
1560+ * @param {Function } run
1561+ * @param {string } frameworkVersion
1562+ * @returns {Function }
1563+ */
1564+ function getWrappedCoordinatorRun ( run , frameworkVersion ) {
1565+ const runAsPromise = function ( numberOfWorkers ) {
1566+ return new Promise ( resolve => run . call ( this , numberOfWorkers , resolve ) )
1567+ }
1568+ const wrappedStart = getWrappedStart ( runAsPromise , frameworkVersion , true )
1569+
1570+ return function ( numberOfWorkers , done ) {
1571+ return wrappedStart . call ( this , numberOfWorkers ) . then ( done )
1572+ }
1573+ }
1574+
15491575module . exports . patchCucumberWorkerRunTestCase = patchCucumberWorkerRunTestCase
15501576
15511577// Test start / finish for older versions. The only hook executed in workers when in parallel mode
@@ -1593,19 +1619,33 @@ addHook({
15931619 return runtimePackage
15941620} )
15951621
1596- // Only executed in parallel mode.
1597- // `getWrappedStart` generates session start and finish events
1622+ // Only executed in parallel mode in Cucumber 7 through 10 .
1623+ // `getWrappedCoordinatorRun` or ` getWrappedStart` generates session start and finish events
15981624// `getWrappedParseWorkerMessage` generates suite start and finish events
1625+ // Shimmer is required because the coordinator must be changed before it starts workers and exposes no lifecycle hook.
15991626addHook ( {
16001627 name : '@cucumber/cucumber' ,
1601- versions : [ '>=8 .0.0 <11.0.0' ] ,
1628+ versions : [ '>=7 .0.0 <11.0.0' ] ,
16021629 file : 'lib/runtime/parallel/coordinator.js' ,
16031630} , ( coordinatorPackage , frameworkVersion ) => {
1604- shimmer . wrap ( coordinatorPackage . default . prototype , 'start' , start => getWrappedStart ( start , frameworkVersion , true ) )
1631+ const isCucumber7 = satisfies ( frameworkVersion , '<8.0.0' )
1632+ if ( isCucumber7 ) {
1633+ shimmer . wrap (
1634+ coordinatorPackage . default . prototype ,
1635+ 'run' ,
1636+ run => getWrappedCoordinatorRun ( run , frameworkVersion )
1637+ )
1638+ } else {
1639+ shimmer . wrap (
1640+ coordinatorPackage . default . prototype ,
1641+ 'start' ,
1642+ start => getWrappedStart ( start , frameworkVersion , true )
1643+ )
1644+ }
16051645 shimmer . wrap (
16061646 coordinatorPackage . default . prototype ,
16071647 'parseWorkerMessage' ,
1608- parseWorkerMessage => getWrappedParseWorkerMessage ( parseWorkerMessage )
1648+ parseWorkerMessage => getWrappedParseWorkerMessage ( parseWorkerMessage , false , isCucumber7 )
16091649 )
16101650 return coordinatorPackage
16111651} )
0 commit comments