From 7eafa08e4aa6e781be3b2c1d376a9cc6ab175ff2 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 4 Sep 2024 11:35:55 +0200 Subject: [PATCH] fix cypress tests --- integration-tests/cypress/cypress.spec.js | 14 +++++++++----- .../datadog-plugin-cypress/src/cypress-plugin.js | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/integration-tests/cypress/cypress.spec.js b/integration-tests/cypress/cypress.spec.js index b6fe70dad78..4bce94316a0 100644 --- a/integration-tests/cypress/cypress.spec.js +++ b/integration-tests/cypress/cypress.spec.js @@ -33,7 +33,8 @@ const { TEST_EARLY_FLAKE_ENABLED, TEST_SUITE, TEST_CODE_OWNERS, - TEST_SESSION_NAME + TEST_SESSION_NAME, + TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants') const { NODE_MAJOR } = require('../../version') @@ -226,6 +227,13 @@ moduleTypes.forEach(({ it('can run and report tests', (done) => { const receiverPromise = receiver .gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => { + const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata) + + metadataDicts.forEach(metadata => { + for (const testLevel of TEST_LEVEL_EVENT_TYPES) { + assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session') + } + }) const events = payloads.flatMap(({ payload }) => payload.events) const testSessionEvent = events.find(event => event.type === 'test_session_end') @@ -236,14 +244,12 @@ moduleTypes.forEach(({ const { content: testSessionEventContent } = testSessionEvent const { content: testModuleEventContent } = testModuleEvent - assert.equal(testSessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session') assert.exists(testSessionEventContent.test_session_id) assert.exists(testSessionEventContent.meta[TEST_COMMAND]) assert.exists(testSessionEventContent.meta[TEST_TOOLCHAIN]) assert.equal(testSessionEventContent.resource.startsWith('test_session.'), true) assert.equal(testSessionEventContent.meta[TEST_STATUS], 'fail') - assert.equal(testModuleEventContent.meta[TEST_SESSION_NAME], 'my-test-session') assert.exists(testModuleEventContent.test_session_id) assert.exists(testModuleEventContent.test_module_id) assert.exists(testModuleEventContent.meta[TEST_COMMAND]) @@ -274,7 +280,6 @@ moduleTypes.forEach(({ test_session_id: testSessionId } }) => { - assert.equal(meta[TEST_SESSION_NAME], 'my-test-session') assert.exists(meta[TEST_COMMAND]) assert.exists(meta[TEST_MODULE]) assert.exists(testSuiteId) @@ -302,7 +307,6 @@ moduleTypes.forEach(({ test_session_id: testSessionId } }) => { - assert.equal(meta[TEST_SESSION_NAME], 'my-test-session') assert.exists(meta[TEST_COMMAND]) assert.exists(meta[TEST_MODULE]) assert.exists(testSuiteId) diff --git a/packages/datadog-plugin-cypress/src/cypress-plugin.js b/packages/datadog-plugin-cypress/src/cypress-plugin.js index 8063b964193..908f048f6ae 100644 --- a/packages/datadog-plugin-cypress/src/cypress-plugin.js +++ b/packages/datadog-plugin-cypress/src/cypress-plugin.js @@ -393,13 +393,15 @@ class CypressPlugin { const testSessionName = getTestSessionName(this.tracer._tracer._config, this.command, this.testEnvironmentMetadata) - const metadataTags = {} - for (const testLevel of TEST_LEVEL_EVENT_TYPES) { - metadataTags[testLevel] = { - [TEST_SESSION_NAME]: testSessionName + if (this.tracer._tracer._exporter?.setMetadataTags) { + const metadataTags = {} + for (const testLevel of TEST_LEVEL_EVENT_TYPES) { + metadataTags[testLevel] = { + [TEST_SESSION_NAME]: testSessionName + } } + this.tracer._tracer._exporter.setMetadataTags(metadataTags) } - this.tracer._exporter.setMetadataTags(metadataTags) this.testSessionSpan = this.tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_session`, { childOf,