Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bin/testObservability/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions test/unit/bin/testObservability/testTags.js
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
Loading