Skip to content

Commit 30c35e9

Browse files
authored
[25 issue] Add suite, parentSuite and subSuite interface (#26)
1 parent 59d03bd commit 30c35e9

14 files changed

+566
-76
lines changed

docs/interface.md

+52
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,58 @@ Adds finished step with passed status.
4141
cy.allure().step('should login');
4242
```
4343

44+
### suite
45+
**suite(name?: string)**
46+
47+
In most cases when you use `describe` plugin will automatically create correct
48+
structure of suites (Suite tab in report), but in some cases you may want to override that
49+
(or add when no describes are being used)
50+
51+
Adds suite to test (or overrides automatic name)
52+
When name is `undefined` it will remove automatic label from test.
53+
54+
```javascript
55+
cy.allure().suite('Suite name');
56+
```
57+
58+
```javascript
59+
cy.allure().suite();
60+
```
61+
62+
### parentSuite
63+
**parentSuite(name?: string)**
64+
65+
In most cases when you use `describe` plugin will automatically create correct
66+
structure of suites (Suite tab in report), but in some cases you may want to override that
67+
(or add when no describes are being used)
68+
69+
Adds parent suite to test (or overrides automatic name)
70+
71+
```javascript
72+
cy.allure().parentSuite('Suite name');
73+
```
74+
75+
```javascript
76+
cy.allure().parentSuite();
77+
```
78+
79+
### subSuite
80+
**subSuite(name?: string)**
81+
82+
In most cases when you use `describe` plugin will automatically create correct
83+
structure of suites (Suite tab in report), but in some cases you may want to override that
84+
(or add when no describes are being used)
85+
86+
Adds sub suite to test (or overrides automatic name)
87+
88+
```javascript
89+
cy.allure().subSuite('Suite name');
90+
```
91+
92+
```javascript
93+
cy.allure().subSuite();
94+
```
95+
4496
### tag
4597
**tag(...tags: string[])**
4698

package-lock.json

+28-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
"@types/ws": "^8.5.5",
7474
"@typescript-eslint/eslint-plugin": "^5.44.0",
7575
"@typescript-eslint/parser": "^5.44.0",
76-
"allure-commandline": "^2.23.1",
77-
"cypress": "^13.0.0",
76+
"allure-commandline": "^2.24.0",
77+
"cypress": "^13.1.0",
7878
"cypress-redirect-browser-log": "^1.1.2",
7979
"eslint": "^8.46.0",
8080
"eslint-config-prettier": "^8.5.0",
@@ -98,12 +98,12 @@
9898
"webpack": "^5.88.2"
9999
},
100100
"dependencies": {
101-
"allure-js-commons": "^2.6.0",
101+
"allure-js-commons": "^2.7.0",
102102
"allure-js-parser": "^0.0.7",
103103
"debug": "^4.3.4",
104104
"fast-glob": "^3.3.1",
105105
"uuid": "^9.0.0",
106106
"uuid-by-string": "^4.0.0",
107-
"ws": "^8.13.0"
107+
"ws": "^8.14.0"
108108
}
109109
}

src/commands/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const registerCommands = () => {
3333
tms: (allure, value, name) => allure.tms(value, name),
3434
issue: (allure, value, name) => allure.issue(value, name),
3535
story: (allure, value) => allure.story(value),
36+
suite: (allure, name) => allure.suite(name),
37+
subSuite: (allure, name) => allure.subSuite(name),
38+
parentSuite: (allure, name) => allure.parentSuite(name),
3639
thread: (allure, value) => allure.thread(value),
3740
allureId: (allure, value) => allure.allureId(value),
3841
// testID: (allure, id) => allure.label('AS_ID', id),

src/cypress/types.ts

+24
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ declare namespace Cypress {
142142
*/
143143
severity(level: Severity): T;
144144

145+
/**
146+
* Adds (or replaces automatic) suite for test
147+
* @param name suite name, when undefined will not use suite
148+
* @example
149+
* cy.allure().suite('test suite');
150+
*/
151+
suite(name?: string): T;
152+
153+
/**
154+
* Adds (or replaces automatic) parent Suite for test
155+
* @param name parent suite name, when undefined will not use parent suite
156+
* @example
157+
* cy.allure().parentSuite('test parent suite');
158+
*/
159+
parentSuite(name?: string): T;
160+
161+
/**
162+
* Adds (or replaces automatic) sub Suite for test
163+
* @param name sub suite name, when undefined will not use sub suite
164+
* @example
165+
* cy.allure().subSuite('test sub suite');
166+
*/
167+
subSuite(name?: string): T;
168+
145169
/**
146170
* Adds thread to test
147171
* @param value string to group in timeline

src/plugins/allure-reporter-plugin.ts

+61-5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class AllureReporter {
5151
groups: AllureGroup[] = [];
5252
tests: AllureTest[] = [];
5353
steps: AllureStep[] = [];
54+
labels: { name: string; value: string }[] = [];
5455
globalHooks = new GlobalHooks(this);
5556

5657
// this is variable for global hooks only
@@ -502,6 +503,37 @@ export class AllureReporter {
502503
}
503504
}
504505

506+
private addGroupLabelByUser(label: string, value?: string) {
507+
if (value === undefined) {
508+
// remove suite labels
509+
this.labels = this.labels.filter(t => t.name !== label);
510+
} else {
511+
this.labels.push({ name: label, value: value });
512+
}
513+
}
514+
515+
suite(arg: AllureTaskArgs<'suite'>) {
516+
if (!this.currentTest) {
517+
return;
518+
}
519+
this.addGroupLabelByUser(LabelName.SUITE, arg.name);
520+
}
521+
522+
parentSuite(arg: AllureTaskArgs<'parentSuite'>) {
523+
if (!this.currentTest) {
524+
return;
525+
}
526+
527+
this.addGroupLabelByUser(LabelName.PARENT_SUITE, arg.name);
528+
}
529+
530+
subSuite(arg: AllureTaskArgs<'subSuite'>) {
531+
if (!this.currentTest) {
532+
return;
533+
}
534+
this.addGroupLabelByUser(LabelName.SUB_SUITE, arg.name);
535+
}
536+
505537
testParameter(arg: AllureTaskArgs<'parameter'>) {
506538
if (this.currentTest) {
507539
this.currentTest.addParameter(arg.name, arg.value);
@@ -524,7 +556,7 @@ export class AllureReporter {
524556
this.executableAttachment(this.currentExecutable, arg);
525557
}
526558

527-
applyGroupLabels() {
559+
addGroupLabels() {
528560
const [parentSuite, suite, subSuite] = this.groups;
529561

530562
if (this.currentSpec) {
@@ -533,15 +565,15 @@ export class AllureReporter {
533565
}
534566

535567
if (this.groups.length > 0) {
536-
this.currentTest?.addLabel(LabelName.PARENT_SUITE, parentSuite.name);
568+
this.labels.push({ name: LabelName.PARENT_SUITE, value: parentSuite.name });
537569
}
538570

539571
if (this.groups.length > 1) {
540-
this.currentTest?.addLabel(LabelName.SUITE, suite.name);
572+
this.labels.push({ name: LabelName.SUITE, value: suite.name });
541573
}
542574

543575
if (this.groups.length > 2) {
544-
this.currentTest?.addLabel(LabelName.SUB_SUITE, subSuite.name);
576+
this.labels.push({ name: LabelName.SUB_SUITE, value: subSuite.name });
545577
}
546578
}
547579

@@ -579,7 +611,7 @@ export class AllureReporter {
579611
test.fullName = fullTitle;
580612

581613
test.historyId = getUuid(fullTitle);
582-
this.applyGroupLabels();
614+
this.addGroupLabels();
583615

584616
if (this.currentSpec?.relative) {
585617
test.addLabel('path', this.currentSpec.relative);
@@ -631,6 +663,28 @@ export class AllureReporter {
631663
this.testDetailsStored = arg;
632664
}
633665

666+
applyGroupLabels() {
667+
// apply labels
668+
669+
const applyLabel = (name: string) => {
670+
if (!this.currentTest) {
671+
return;
672+
}
673+
const lb = this.labels.filter(l => l.name == name);
674+
675+
// return last added
676+
const lastLabel = lb[lb.length - 1];
677+
678+
if (lastLabel) {
679+
this.currentTest.addLabel(lastLabel.name, lastLabel.value);
680+
}
681+
};
682+
683+
applyLabel(LabelName.PARENT_SUITE);
684+
applyLabel(LabelName.SUITE);
685+
applyLabel(LabelName.SUB_SUITE);
686+
}
687+
634688
endTest(arg: AllureTaskArgs<'testEnded'>) {
635689
const { result, details } = arg;
636690
const storedStatus = this.testStatusStored;
@@ -663,12 +717,14 @@ export class AllureReporter {
663717
this.setExecutableStatus(this.currentTest, storedStatus.result, storedStatus.details);
664718
}
665719

720+
this.applyGroupLabels();
666721
this.currentTest.endTest();
667722

668723
this.tests.pop();
669724
this.descriptionHtml = [];
670725
this.testStatusStored = undefined;
671726
this.testDetailsStored = undefined;
727+
this.labels = [];
672728
}
673729

674730
startStep(arg: AllureTaskArgs<'stepStarted'>) {

src/plugins/allure-types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type AllureTask = {
4646
addDescriptionHtml: { value: string };
4747
label: { name: string; value: string };
4848
message: { name: string };
49+
suite: { name?: string };
50+
subSuite: { name?: string };
51+
parentSuite: { name?: string };
4952
testMessage: { path: string; message: string };
5053
delete: { path: string };
5154
attachScreenshots: { screenshots: AutoScreen[] };

0 commit comments

Comments
 (0)