Skip to content

Commit

Permalink
add browser name
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Feb 12, 2024
1 parent 7561fb5 commit a704374
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
25 changes: 21 additions & 4 deletions packages/datadog-instrumentations/src/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,24 @@ function getRootDir (playwrightRunner) {
return process.cwd()
}

function testBeginHandler (test) {
const { _requireFile: testSuiteAbsolutePath, title: testName, _type, location: { line: testSourceLine } } = test
function getProjectsFromDispatcher (dispatcher) {
return dispatcher?._config?.config?.projects
}

function getBrowserNameFromProjectId (dispatcher, projectId) {
const projects = getProjectsFromDispatcher(dispatcher)
if (projects) {
return projects.find(project => project.__projectId === projectId)?.name
}
return null
}

function testBeginHandler (test, browserName) {
const {
_requireFile: testSuiteAbsolutePath,
title: testName, _type,
location: { line: testSourceLine }
} = test

if (_type === 'beforeAll' || _type === 'afterAll') {
return
Expand All @@ -100,7 +116,7 @@ function testBeginHandler (test) {
const testAsyncResource = new AsyncResource('bound-anonymous-fn')
testToAr.set(test, testAsyncResource)
testAsyncResource.runInAsyncScope(() => {
testStartCh.publish({ testName, testSuiteAbsolutePath, testSourceLine })
testStartCh.publish({ testName, testSuiteAbsolutePath, testSourceLine, browserName })
})
}

Expand Down Expand Up @@ -203,7 +219,8 @@ function dispatcherHookNew (dispatcherExport, runWrapper) {

worker.on('testBegin', ({ testId }) => {
const test = getTestByTestId(dispatcher, testId)
testBeginHandler(test)
const browser = getBrowserNameFromProjectId(dispatcher, test._projectId)
testBeginHandler(test, browser)
})
worker.on('testEnd', ({ testId, status, errors, annotations }) => {
const test = getTestByTestId(dispatcher, testId)
Expand Down
12 changes: 8 additions & 4 deletions packages/datadog-plugin-playwright/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {
getTestSuiteCommonTags,
TEST_SOURCE_START,
TEST_CODE_OWNERS,
TEST_SOURCE_FILE
TEST_SOURCE_FILE,
TEST_CONFIGURATION_BROWSER_NAME
} = require('../../dd-trace/src/plugins/util/test')
const { RESOURCE_NAME } = require('../../../ext/tags')
const { COMPONENT } = require('../../dd-trace/src/constants')
Expand Down Expand Up @@ -77,11 +78,11 @@ class PlaywrightPlugin extends CiPlugin {
this.telemetry.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'suite')
})

this.addSub('ci:playwright:test:start', ({ testName, testSuiteAbsolutePath, testSourceLine }) => {
this.addSub('ci:playwright:test:start', ({ testName, testSuiteAbsolutePath, testSourceLine, browserName }) => {
const store = storage.getStore()
const testSuite = getTestSuitePath(testSuiteAbsolutePath, this.rootDir)
const testSourceFile = getTestSuitePath(testSuiteAbsolutePath, this.repositoryRoot)
const span = this.startTestSpan(testName, testSuite, testSourceFile, testSourceLine)
const span = this.startTestSpan(testName, testSuite, testSourceFile, testSourceLine, browserName)

this.enter(span, store)
})
Expand Down Expand Up @@ -128,7 +129,7 @@ class PlaywrightPlugin extends CiPlugin {
})
}

startTestSpan (testName, testSuite, testSourceFile, testSourceLine) {
startTestSpan (testName, testSuite, testSourceFile, testSourceLine, browserName) {
const testSuiteSpan = this._testSuites.get(testSuite)

const extraTags = {
Expand All @@ -137,6 +138,9 @@ class PlaywrightPlugin extends CiPlugin {
if (testSourceFile) {
extraTags[TEST_SOURCE_FILE] = testSourceFile || testSuite
}
if (browserName) {
extraTags[TEST_CONFIGURATION_BROWSER_NAME] = browserName
}

return super.startTestSpan(testName, testSuite, testSuiteSpan, extraTags)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const TEST_MODULE_ID = 'test_module_id'
const TEST_SUITE_ID = 'test_suite_id'
const TEST_TOOLCHAIN = 'test.toolchain'
const TEST_SKIPPED_BY_ITR = 'test.skipped_by_itr'
// Browser used in browser test. Namespaced by test.configuration because it affects the fingerprint
const TEST_CONFIGURATION_BROWSER_NAME = 'test.configuration.browser_name'
// Early flake detection
const TEST_IS_NEW = 'test.is_new'
const TEST_EARLY_FLAKE_IS_RETRY = 'test.early_flake.is_retry'
const TEST_EARLY_FLAKE_IS_ENABLED = 'test.early_flake.is_enabled'
Expand Down Expand Up @@ -90,6 +93,7 @@ module.exports = {
JEST_WORKER_COVERAGE_PAYLOAD_CODE,
TEST_SOURCE_START,
TEST_SKIPPED_BY_ITR,
TEST_CONFIGURATION_BROWSER_NAME,
TEST_IS_NEW,
TEST_EARLY_FLAKE_IS_RETRY,
TEST_EARLY_FLAKE_IS_ENABLED,
Expand Down

0 comments on commit a704374

Please sign in to comment.