Skip to content

Commit d71520e

Browse files
Mariovidosabrenner
authored andcommitted
[test-optimization] [SDTEST-2548] Fix playwright instrumentation for versions >=1.55.0 (#6330)
1 parent df801fb commit d71520e

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

packages/datadog-instrumentations/src/playwright.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function getPlaywrightConfig (playwrightRunner) {
148148
}
149149
}
150150

151-
function getRootDir (playwrightRunner) {
152-
const config = getPlaywrightConfig(playwrightRunner)
151+
function getRootDir (playwrightRunner, configArg) {
152+
const config = configArg ? configArg.config : getPlaywrightConfig(playwrightRunner)
153153
if (config.rootDir) {
154154
return config.rootDir
155155
}
@@ -162,8 +162,8 @@ function getRootDir (playwrightRunner) {
162162
return process.cwd()
163163
}
164164

165-
function getProjectsFromRunner (runner) {
166-
const config = getPlaywrightConfig(runner)
165+
function getProjectsFromRunner (runner, configArg) {
166+
const config = configArg || getPlaywrightConfig(runner)
167167
return config.projects?.map((project) => {
168168
if (project.project) {
169169
return project.project
@@ -509,11 +509,12 @@ function dispatcherHookNew (dispatcherExport, runWrapper) {
509509
return dispatcherExport
510510
}
511511

512-
function runnerHook (runnerExport, playwrightVersion) {
513-
shimmer.wrap(runnerExport.Runner.prototype, 'runAllTests', runAllTests => async function () {
512+
function runAllTestsWrapper (runAllTests, playwrightVersion) {
513+
// Config parameter is only available from >=1.55.0
514+
return async function (config) {
514515
let onDone
515516

516-
rootDir = getRootDir(this)
517+
rootDir = getRootDir(this, config)
517518

518519
const processArgv = process.argv.slice(2).join(' ')
519520
const command = `playwright ${processArgv}`
@@ -586,7 +587,7 @@ function runnerHook (runnerExport, playwrightVersion) {
586587
}
587588
}
588589

589-
const projects = getProjectsFromRunner(this)
590+
const projects = getProjectsFromRunner(this, config)
590591

591592
const shouldSetRetries = isFlakyTestRetriesEnabled &&
592593
flakyTestRetriesCount > 0 &&
@@ -651,6 +652,23 @@ function runnerHook (runnerExport, playwrightVersion) {
651652
// TODO: we can trick playwright into thinking the session passed by returning
652653
// 'passed' here. We might be able to use this for both EFD and Test Management tests.
653654
return runAllTestsReturn
655+
}
656+
}
657+
658+
function runnerHook (runnerExport, playwrightVersion) {
659+
shimmer.wrap(
660+
runnerExport.Runner.prototype,
661+
'runAllTests',
662+
runAllTests => runAllTestsWrapper(runAllTests, playwrightVersion)
663+
)
664+
}
665+
666+
function runnerHookNew (runnerExport, playwrightVersion) {
667+
runnerExport = shimmer.wrap(runnerExport, 'runAllTestsWithConfig', function (originalGetter) {
668+
const originalFunction = originalGetter.call(this)
669+
return function () {
670+
return runAllTestsWrapper(originalFunction, playwrightVersion)
671+
}
654672
})
655673

656674
return runnerExport
@@ -694,6 +712,12 @@ addHook({
694712
versions: ['>=1.38.0']
695713
}, runnerHook)
696714

715+
addHook({
716+
name: 'playwright',
717+
file: 'lib/runner/testRunner.js',
718+
versions: ['>=1.55.0']
719+
}, runnerHookNew)
720+
697721
addHook({
698722
name: 'playwright',
699723
file: 'lib/runner/dispatcher.js',

0 commit comments

Comments
 (0)