Skip to content

Commit

Permalink
[ci-visibility] Change test.type in browser tests (#3358)
Browse files Browse the repository at this point in the history
* Add framework type checking

* Improve code readability

Co-authored-by: Juan Antonio Fernández de Alba <juan.fernandezdealba@datadoghq.com>

* Fix imports

* Fix styling

Co-authored-by: Juan Antonio Fernández de Alba <juan.fernandezdealba@datadoghq.com>

* Add cypress and playwright tests

* Change browser conditions to detect all playwright instances

* Fix include string

* Fix some suites still being reported as test type

---------

Co-authored-by: Juan Antonio Fernández de Alba <juan.fernandezdealba@datadoghq.com>
  • Loading branch information
2 people authored and Qard committed Jul 14, 2023
1 parent b16a5e8 commit fd409f1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
5 changes: 3 additions & 2 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
} = require('../helpers')
const { FakeCiVisIntake } = require('../ci-visibility-intake')
const webAppServer = require('../ci-visibility/web-app-server')
const { TEST_STATUS, TEST_SOURCE_START } = require('../../packages/dd-trace/src/plugins/util/test')
const { TEST_STATUS, TEST_SOURCE_START, TEST_TYPE } = require('../../packages/dd-trace/src/plugins/util/test')

// TODO: remove when 2.x support is removed.
// This is done because from playwright@>=1.22.0 node 12 is not supported
Expand Down Expand Up @@ -73,7 +73,8 @@ versions.forEach((version) => {
assert.equal(testSessionEvent.content.meta[TEST_STATUS], 'fail')
assert.include(testModuleEvent.content.resource, 'test_module.playwright test')
assert.equal(testModuleEvent.content.meta[TEST_STATUS], 'fail')

assert.equal(testSessionEvent.content.meta[TEST_TYPE], 'browser')
assert.equal(testModuleEvent.content.meta[TEST_TYPE], 'browser')
assert.includeMembers(testSuiteEvents.map(suite => suite.content.resource), [
'test_suite.todo-list-page-test.js',
'test_suite.landing-page-test.js',
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-cypress/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CYPRESS_STATUS_TO_TEST_STATUS = {
function getTestSpanMetadata (tracer, testName, testSuite, cypressConfig) {
const childOf = getTestParentSpan(tracer)

const commonTags = getTestCommonTags(testName, testSuite, cypressConfig.version)
const commonTags = getTestCommonTags(testName, testSuite, cypressConfig.version, TEST_FRAMEWORK_NAME)

return {
childOf,
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-plugin-cypress/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Plugin', function () {
[TEST_STATUS]: 'pass',
[TEST_SUITE]: 'cypress/integration/integration-test.js',
[TEST_SOURCE_FILE]: 'cypress/integration/integration-test.js',
[TEST_TYPE]: 'test',
[TEST_TYPE]: 'browser',
[ORIGIN_KEY]: CI_APP_ORIGIN,
[TEST_IS_RUM_ACTIVE]: 'true',
[TEST_CODE_OWNERS]: JSON.stringify(['@datadog']),
Expand All @@ -103,7 +103,7 @@ describe('Plugin', function () {
[TEST_STATUS]: 'fail',
[TEST_SUITE]: 'cypress/integration/integration-test.js',
[TEST_SOURCE_FILE]: 'cypress/integration/integration-test.js',
[TEST_TYPE]: 'test',
[TEST_TYPE]: 'browser',
[ORIGIN_KEY]: CI_APP_ORIGIN,
[ERROR_TYPE]: 'AssertionError',
[TEST_IS_RUM_ACTIVE]: 'true',
Expand Down
7 changes: 6 additions & 1 deletion packages/dd-trace/src/plugins/ci_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ module.exports = class CiPlugin extends Plugin {
const childOf = getTestParentSpan(this.tracer)

let testTags = {
...getTestCommonTags(testName, testSuite, this.frameworkVersion),
...getTestCommonTags(
testName,
testSuite,
this.frameworkVersion,
this.constructor.id
),
[COMPONENT]: this.constructor.id,
...extraTags
}
Expand Down
21 changes: 14 additions & 7 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ function getTestParametersString (parametersByTestName, testName) {
}
}

function getTestTypeFromFramework (testFramework) {
if (testFramework === 'playwright' || testFramework === 'cypress') {
return 'browser'
}
return 'test'
}

function finishAllTraceSpans (span) {
span.context()._trace.started.forEach(traceSpan => {
if (traceSpan !== span) {
Expand All @@ -225,10 +232,10 @@ function getTestParentSpan (tracer) {
})
}

function getTestCommonTags (name, suite, version) {
function getTestCommonTags (name, suite, version, testFramework) {
return {
[SPAN_TYPE]: 'test',
[TEST_TYPE]: 'test',
[TEST_TYPE]: getTestTypeFromFramework(testFramework),
[SAMPLING_RULE_DECISION]: 1,
[SAMPLING_PRIORITY]: AUTO_KEEP,
[TEST_NAME]: name,
Expand Down Expand Up @@ -306,12 +313,12 @@ function getCodeOwnersForFilename (filename, entries) {
return null
}

function getTestLevelCommonTags (command, testFrameworkVersion) {
function getTestLevelCommonTags (command, testFrameworkVersion, testFramework) {
return {
[TEST_FRAMEWORK_VERSION]: testFrameworkVersion,
[LIBRARY_VERSION]: ddTraceVersion,
[TEST_COMMAND]: command,
[TEST_TYPE]: 'test'
[TEST_TYPE]: getTestTypeFromFramework(testFramework)
}
}

Expand All @@ -321,7 +328,7 @@ function getTestSessionCommonTags (command, testFrameworkVersion, testFramework)
[RESOURCE_NAME]: `test_session.${command}`,
[TEST_MODULE]: testFramework,
[TEST_TOOLCHAIN]: getPkgManager(),
...getTestLevelCommonTags(command, testFrameworkVersion)
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
}
}

Expand All @@ -330,7 +337,7 @@ function getTestModuleCommonTags (command, testFrameworkVersion, testFramework)
[SPAN_TYPE]: 'test_module_end',
[RESOURCE_NAME]: `test_module.${command}`,
[TEST_MODULE]: testFramework,
...getTestLevelCommonTags(command, testFrameworkVersion)
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
}
}

Expand All @@ -340,7 +347,7 @@ function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite, testF
[RESOURCE_NAME]: `test_suite.${testSuite}`,
[TEST_MODULE]: testFramework,
[TEST_SUITE]: testSuite,
...getTestLevelCommonTags(command, testFrameworkVersion)
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
}
}

Expand Down

0 comments on commit fd409f1

Please sign in to comment.