diff --git a/cypress.config.ts b/cypress.config.ts index 30b50e2..17980e9 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -17,6 +17,9 @@ export default defineConfig({ toConsole: false, }, video: false, + env: { + cyTagsShowTagsInTitle: false, + }, setupNodeEvents(on, config) { setupPlugins(on, config); diff --git a/integration/e2e/suite-example.test.ts b/integration/e2e/suite-example.test.ts new file mode 100644 index 0000000..ab3edc2 --- /dev/null +++ b/integration/e2e/suite-example.test.ts @@ -0,0 +1,70 @@ +describe('cyTagsShowTagsInTitle', () => { + describe('is false', () => { + describe('suite with tag @suiteTag', () => { + describe('suite with tag @apple', () => { + it('test @tag', function () { + cy.log(`cyTagsShowTagsInTitle ${Cypress.env('cyTagsShowTagsInTitle')}`); + + if (Cypress.env('cyTagsShowTagsInTitle') === 'false' || Cypress.env('cyTagsShowTagsInTitle') === false) { + expect(this.test?.tags).deep.eq([ + { tag: '@tag', info: [] }, + { tag: '@apple', info: [] }, + { tag: '@suiteTag', info: [] }, + ]); + expect(this.test?.title).eq('test'); + expect(this.test?.fullTitle()).eq('cyTagsShowTagsInTitle is false suite with tag suite with tag test'); + } else { + this.skip(); + } + }); + }); + }); + }); + + describe('is true', () => { + describe('suite with tag @suiteTag', () => { + describe('suite with tag @apple', () => { + it('test @tag', function () { + cy.log(`cyTagsShowTagsInTitle ${Cypress.env('cyTagsShowTagsInTitle')}`); + + if (Cypress.env('cyTagsShowTagsInTitle') === 'true' || Cypress.env('cyTagsShowTagsInTitle') === true) { + expect(this.test?.tags).deep.eq([ + { tag: '@tag', info: [] }, + { tag: '@apple', info: [] }, + { tag: '@suiteTag', info: [] }, + ]); + expect(this.test?.title).eq('test@tag'); + expect(this.test?.fullTitle()).eq( + 'cyTagsShowTagsInTitle is true suite with tag @suiteTag suite with tag @apple @suiteTag test@tag', + ); + } else { + this.skip(); + } + }); + }); + }); + }); + describe('is undefined', () => { + describe('suite with tag @suiteTag', () => { + describe('suite with tag @apple', () => { + it('test @tag', function () { + cy.log(`cyTagsShowTagsInTitle ${Cypress.env('cyTagsShowTagsInTitle')}`); + + if (Cypress.env('cyTagsShowTagsInTitle') === undefined) { + expect(this.test?.tags).deep.eq([ + { tag: '@tag', info: [] }, + { tag: '@apple', info: [] }, + { tag: '@suiteTag', info: [] }, + ]); + expect(this.test?.title).eq('test @tag'); + expect(this.test?.fullTitle()).eq( + 'cyTagsShowTagsInTitle is undefined suite with tag @suiteTag suite with tag @apple test @tag', + ); + } else { + this.skip(); + } + }); + }); + }); + }); +}); diff --git a/src/mocha/index.ts b/src/mocha/index.ts index 9003c80..b034a6a 100644 --- a/src/mocha/index.ts +++ b/src/mocha/index.ts @@ -6,6 +6,10 @@ namespace Mocha { tags?: GrepTagObject[]; } + export interface Suite { + tags?: GrepTagObject[]; + } + export interface Runnable { tags?: GrepTagObject[]; } diff --git a/src/setup/index.ts b/src/setup/index.ts index 7cc2b12..7072df3 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -80,6 +80,7 @@ export const registerTags = () => { */ const suiteTitleChange = (rootSuite: Mocha.Suite, setting: { showTagsInTitle?: boolean }) => { const suiteTags = parseAll(rootSuite, []); + rootSuite.tags = uniqTags([...suiteTags, ...(rootSuite.tags ?? [])]); if (setting.showTagsInTitle !== undefined) { rootSuite.title = removeTagsFromTitle(rootSuite.title); @@ -125,10 +126,10 @@ export const registerTags = () => { suite.eachTest(st => { testProcess(st); }); - } - if (showTagsInTitle() !== undefined) { - suiteTitleChange(suite, { showTagsInTitle: showTagsInTitle() }); + if (showTagsInTitle() !== undefined) { + suiteTitleChange(suite, { showTagsInTitle: showTagsInTitle() }); + } } return suite;