Skip to content

Commit

Permalink
fix removing tags from title - attempt2 [patch]
Browse files Browse the repository at this point in the history
  • Loading branch information
mmisty committed Nov 2, 2023
1 parent a33b9b4 commit 43c45fe
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default defineConfig({
toConsole: false,
},
video: false,
env: {
cyTagsShowTagsInTitle: false,
},

setupNodeEvents(on, config) {
setupPlugins(on, config);
Expand Down
70 changes: 70 additions & 0 deletions integration/e2e/suite-example.test.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
});
});
});
});
4 changes: 4 additions & 0 deletions src/mocha/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace Mocha {
tags?: GrepTagObject[];
}

export interface Suite {
tags?: GrepTagObject[];
}

export interface Runnable {
tags?: GrepTagObject[];
}
Expand Down
7 changes: 4 additions & 3 deletions src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 43c45fe

Please sign in to comment.