|
| 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