From fa89263ac06135d3f1b24cd1fb543375695d1e04 Mon Sep 17 00:00:00 2001 From: rounak bhatia Date: Mon, 23 Nov 2026 16:28:35 +0530 Subject: [PATCH] SDK-7389: send per-test tags to Test Observability Tags set in a test's Cypress config (it/describe { tags: [...] }) never reached Test Observability: the reporter built TestRun events without a tags field, so details.tags was always empty. Cypress already passes each test's config to the reporter as test._testConfig, so read the tags from there (resolved testConfigList on current Cypress, raw overrides on older versions) and add them to TestRun events. Co-Authored-By: Claude Opus 5.5 --- bin/testObservability/reporter/index.js | 27 +++++++++++++ test/unit/bin/testObservability/testTags.js | 43 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/unit/bin/testObservability/testTags.js diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 058b521b..93f97a75 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -451,6 +451,10 @@ class MyReporter { } }; + if(eventType.match(/TestRun/)) { + testData.tags = this.tags(test); + } + debugOnConsole(`${eventType} for uuid: ${testData.uuid}`); this.mapTestId(testData, eventType); @@ -875,6 +879,29 @@ class MyReporter { return titlePath.slice(0, titlePath.length - 1) } + // Tags come from the it()/describe() config. Newer Cypress sends it resolved as + // { testConfigList: [{ overrides }, ...] }, one entry per level; older versions send the raw overrides. + tags(test) { + try { + const testConfig = test && test._testConfig; + if (!testConfig) return []; + const overridesList = Array.isArray(testConfig.testConfigList) + ? testConfig.testConfigList.map((entry) => entry && entry.overrides) + : [testConfig]; + const tags = []; + overridesList.forEach((overrides) => { + const value = overrides && overrides.tags; + (Array.isArray(value) ? value : [value]).forEach((tag) => { + const name = typeof tag === 'string' ? tag.trim() : ''; + if (name && !tags.includes(name)) tags.push(name); + }); + }); + return tags; + } catch (e) { + return []; + } + } + // Recursively find the root parent, and return the parents file // This is required as test.file can be undefined in some tests on cypress getRootParentFile(test) { diff --git a/test/unit/bin/testObservability/testTags.js b/test/unit/bin/testObservability/testTags.js new file mode 100644 index 00000000..40b37701 --- /dev/null +++ b/test/unit/bin/testObservability/testTags.js @@ -0,0 +1,43 @@ +'use strict'; +const chai = require('chai'); +const expect = chai.expect; + +const MyReporter = require('../../../../bin/testObservability/reporter'); + +// SDK-7389: per-test tags set via it()/describe() config must reach the TestRun events. +describe('testObservability reporter tags', () => { + const tags = (test) => MyReporter.prototype.tags.call({}, test); + + it('collects suite and test level tags from the resolved test config', () => { + const test = { + _testConfig: { + testConfigList: [ + { overrideLevel: 'suite', overrides: { tags: ['@suite_tag'] } }, + { overrideLevel: 'test', overrides: { tags: ['@test_tag'], retries: 1 } } + ], + unverifiedTestConfig: { tags: ['@test_tag'], retries: 1 } + } + }; + expect(tags(test)).to.deep.equal(['@suite_tag', '@test_tag']); + }); + + it('accepts a single string tag', () => { + const test = { _testConfig: { testConfigList: [{ overrides: { tags: '@smoke' } }] } }; + expect(tags(test)).to.deep.equal(['@smoke']); + }); + + it('reads the raw overrides object sent by older Cypress versions', () => { + expect(tags({ _testConfig: { tags: ['@a', '@b'] } })).to.deep.equal(['@a', '@b']); + }); + + it('trims, de-duplicates and drops non-string or empty tags', () => { + const test = { _testConfig: { testConfigList: [{ overrides: { tags: [' @a ', '@a', 5, null, '', ' '] } }] } }; + expect(tags(test)).to.deep.equal(['@a']); + }); + + it('returns an empty list when the test has no tags', () => { + expect(tags({})).to.deep.equal([]); + expect(tags(undefined)).to.deep.equal([]); + expect(tags({ _testConfig: { testConfigList: [{ overrides: { retries: 2 } }, null] } })).to.deep.equal([]); + }); +});