Skip to content

Commit fa89263

Browse files
rounak610claude
andcommitted
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 <noreply@anthropic.com>
1 parent aedf9e9 commit fa89263

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎bin/testObservability/reporter/index.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ class MyReporter {
451451
}
452452
};
453453

454+
if(eventType.match(/TestRun/)) {
455+
testData.tags = this.tags(test);
456+
}
457+
454458
debugOnConsole(`${eventType} for uuid: ${testData.uuid}`);
455459

456460
this.mapTestId(testData, eventType);
@@ -875,6 +879,29 @@ class MyReporter {
875879
return titlePath.slice(0, titlePath.length - 1)
876880
}
877881

882+
// Tags come from the it()/describe() config. Newer Cypress sends it resolved as
883+
// { testConfigList: [{ overrides }, ...] }, one entry per level; older versions send the raw overrides.
884+
tags(test) {
885+
try {
886+
const testConfig = test && test._testConfig;
887+
if (!testConfig) return [];
888+
const overridesList = Array.isArray(testConfig.testConfigList)
889+
? testConfig.testConfigList.map((entry) => entry && entry.overrides)
890+
: [testConfig];
891+
const tags = [];
892+
overridesList.forEach((overrides) => {
893+
const value = overrides && overrides.tags;
894+
(Array.isArray(value) ? value : [value]).forEach((tag) => {
895+
const name = typeof tag === 'string' ? tag.trim() : '';
896+
if (name && !tags.includes(name)) tags.push(name);
897+
});
898+
});
899+
return tags;
900+
} catch (e) {
901+
return [];
902+
}
903+
}
904+
878905
// Recursively find the root parent, and return the parents file
879906
// This is required as test.file can be undefined in some tests on cypress
880907
getRootParentFile(test) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
const chai = require('chai');
3+
const expect = chai.expect;
4+
5+
const MyReporter = require('../../../../bin/testObservability/reporter');
6+
7+
// SDK-7389: per-test tags set via it()/describe() config must reach the TestRun events.
8+
describe('testObservability reporter tags', () => {
9+
const tags = (test) => MyReporter.prototype.tags.call({}, test);
10+
11+
it('collects suite and test level tags from the resolved test config', () => {
12+
const test = {
13+
_testConfig: {
14+
testConfigList: [
15+
{ overrideLevel: 'suite', overrides: { tags: ['@suite_tag'] } },
16+
{ overrideLevel: 'test', overrides: { tags: ['@test_tag'], retries: 1 } }
17+
],
18+
unverifiedTestConfig: { tags: ['@test_tag'], retries: 1 }
19+
}
20+
};
21+
expect(tags(test)).to.deep.equal(['@suite_tag', '@test_tag']);
22+
});
23+
24+
it('accepts a single string tag', () => {
25+
const test = { _testConfig: { testConfigList: [{ overrides: { tags: '@smoke' } }] } };
26+
expect(tags(test)).to.deep.equal(['@smoke']);
27+
});
28+
29+
it('reads the raw overrides object sent by older Cypress versions', () => {
30+
expect(tags({ _testConfig: { tags: ['@a', '@b'] } })).to.deep.equal(['@a', '@b']);
31+
});
32+
33+
it('trims, de-duplicates and drops non-string or empty tags', () => {
34+
const test = { _testConfig: { testConfigList: [{ overrides: { tags: [' @a ', '@a', 5, null, '', ' '] } }] } };
35+
expect(tags(test)).to.deep.equal(['@a']);
36+
});
37+
38+
it('returns an empty list when the test has no tags', () => {
39+
expect(tags({})).to.deep.equal([]);
40+
expect(tags(undefined)).to.deep.equal([]);
41+
expect(tags({ _testConfig: { testConfigList: [{ overrides: { retries: 2 } }, null] } })).to.deep.equal([]);
42+
});
43+
});

0 commit comments

Comments
 (0)