Skip to content

Commit f67b151

Browse files
authored
[patch] fix of #59 issue and update cypress (#60)
1 parent fb828a1 commit f67b151

File tree

6 files changed

+220
-10
lines changed

6 files changed

+220
-10
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Change Log
2+
### 0.12.3
3+
- [tech] update cypress 13.3.4
4+
- fix of #59 issue
25
### 0.12.2
36
- small local dependancy issue
47
### 0.12.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
describe('before each fail with retry - first in test then in hook @beforeEachRetry', { retries: 2 }, () => {
2+
beforeEach('Named hook', function () {
3+
cy.log('before each');
4+
5+
if (Cypress.currentRetry > 1 && this.currentTest?.title?.indexOf('test 05') !== -1) {
6+
// throw new Error('Fail in hook');
7+
cy.wrap(null).then(() => {
8+
throw new Error('Fail in hook');
9+
});
10+
}
11+
});
12+
13+
for (let i = 1; i <= 10; i++) {
14+
it(`test ${`0${i}`.slice(-2)}`, function () {
15+
cy.log(`test ${i}`);
16+
17+
if (this.test?.title.indexOf('test 05') !== -1) {
18+
cy.wrap(null).then(() => {
19+
throw new Error('Fail in test');
20+
});
21+
}
22+
});
23+
}
24+
});

package-lock.json

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@typescript-eslint/eslint-plugin": "^5.44.0",
8989
"@typescript-eslint/parser": "^5.44.0",
9090
"allure-commandline": "^2.24.0",
91-
"cypress": "^13.3.3",
91+
"cypress": "^13.3.4",
9292
"cypress-redirect-browser-log": "^1.1.2",
9393
"eslint": "^8.46.0",
9494
"eslint-config-prettier": "^8.5.0",

src/setup/allure-mocha-reporter.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,28 @@ const createTests = (runner: Mocha.Runner, test: Mocha.Test) => {
193193
});
194194
};
195195

196+
/**
197+
* Will create synthetic tests that were not run for allure report with unknown status
198+
* @param runner
199+
* @param test - hook that failed
200+
*/
196201
const createTestsBeforeEach = (runner: Mocha.Runner, test: Mocha.Test) => {
197202
let index = 0;
203+
let failedIndex = 0;
204+
let found = false;
205+
198206
test.parent?.eachTest(ts => {
199207
ts.err = test.err;
200-
208+
// test.title is hook title like ""before each" hook: Named hook for "test 05""
209+
const startFrom = test.title.indexOf(ts.title);
201210
index++;
202211

203-
if (index !== 1 && ts) {
212+
if (!found && startFrom !== -1) {
213+
found = true;
214+
failedIndex = index;
215+
}
216+
217+
if (found && index > failedIndex) {
204218
runner.emit(CUSTOM_EVENTS.TEST_BEGIN, ts);
205219
runner.emit(CUSTOM_EVENTS.TEST_FAIL, ts);
206220
runner.emit(CUSTOM_EVENTS.TEST_END, ts);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { createResTest2, fixResult } from '../../../cy-helper/utils';
2+
import { AllureTest, parseAllure } from 'allure-js-parser';
3+
4+
describe('should have all hooks and steps inside', () => {
5+
const res = createResTest2(
6+
[
7+
`
8+
describe('before each fail with retry - first in test then in hook @beforeEachRetry', { retries: 2 }, () => {
9+
beforeEach('Named hook', function () {
10+
cy.log('before each');
11+
12+
if (Cypress.currentRetry > 1 && this.currentTest?.title?.indexOf('test 05') !== -1) {
13+
cy.wrap(null).then(() => {
14+
throw new Error('Fail in hook');
15+
});
16+
}
17+
});
18+
19+
for (let i = 1; i <= 10; i++) {
20+
it('test ' + ('0'+i).slice(-2), function () {
21+
cy.log('test ' + i);
22+
23+
if (this.test?.title.indexOf('test 05') !== -1) {
24+
cy.wrap(null).then(() => {
25+
throw new Error('Fail in test');
26+
});
27+
}
28+
});
29+
}
30+
});
31+
32+
`,
33+
],
34+
{ allureAddVideoOnPass: 'true' },
35+
);
36+
37+
describe('check results', () => {
38+
let resFixed: AllureTest[];
39+
let results: AllureTest[];
40+
41+
beforeAll(() => {
42+
results = parseAllure(res.watch);
43+
resFixed = fixResult(results);
44+
});
45+
46+
it('check tests count', async () => {
47+
expect(resFixed.length).toEqual(12);
48+
});
49+
50+
it('check tests names', async () => {
51+
expect(resFixed.map(t => t.fullName).sort()).toEqual([
52+
'before each fail with retry - first in test then in hook @beforeEachRetry test 01',
53+
'before each fail with retry - first in test then in hook @beforeEachRetry test 02',
54+
'before each fail with retry - first in test then in hook @beforeEachRetry test 03',
55+
'before each fail with retry - first in test then in hook @beforeEachRetry test 04',
56+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
57+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
58+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
59+
'before each fail with retry - first in test then in hook @beforeEachRetry test 06',
60+
'before each fail with retry - first in test then in hook @beforeEachRetry test 07',
61+
'before each fail with retry - first in test then in hook @beforeEachRetry test 08',
62+
'before each fail with retry - first in test then in hook @beforeEachRetry test 09',
63+
'before each fail with retry - first in test then in hook @beforeEachRetry test 10',
64+
]);
65+
});
66+
67+
it('check statuses and details', () => {
68+
expect(
69+
results
70+
.map(t => ({
71+
fullName: t.fullName,
72+
name: t.name,
73+
status: t.status,
74+
message: t.statusDetails.message,
75+
start: t.start,
76+
}))
77+
.sort((a, b) => (a.start && b.start && a.start < b.start ? -1 : 1))
78+
.map(x => ({ ...x, start: undefined })),
79+
).toEqual([
80+
{
81+
fullName:
82+
'before each fail with retry - first in test then in hook @beforeEachRetry test 01',
83+
name: 'test 01',
84+
status: 'passed',
85+
},
86+
{
87+
fullName:
88+
'before each fail with retry - first in test then in hook @beforeEachRetry test 02',
89+
name: 'test 02',
90+
status: 'passed',
91+
},
92+
{
93+
fullName:
94+
'before each fail with retry - first in test then in hook @beforeEachRetry test 03',
95+
name: 'test 03',
96+
status: 'passed',
97+
},
98+
{
99+
fullName:
100+
'before each fail with retry - first in test then in hook @beforeEachRetry test 04',
101+
name: 'test 04',
102+
status: 'passed',
103+
},
104+
{
105+
fullName:
106+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
107+
message: 'Fail in test',
108+
name: 'test 05',
109+
status: 'failed',
110+
},
111+
{
112+
fullName:
113+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
114+
message: 'Fail in test',
115+
name: 'test 05',
116+
status: 'failed',
117+
},
118+
{
119+
fullName:
120+
'before each fail with retry - first in test then in hook @beforeEachRetry test 05',
121+
message:
122+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
123+
name: 'test 05',
124+
status: 'failed',
125+
},
126+
{
127+
fullName:
128+
'before each fail with retry - first in test then in hook @beforeEachRetry test 06',
129+
message:
130+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
131+
name: 'test 06',
132+
status: 'unknown',
133+
},
134+
{
135+
fullName:
136+
'before each fail with retry - first in test then in hook @beforeEachRetry test 07',
137+
message:
138+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
139+
name: 'test 07',
140+
status: 'unknown',
141+
},
142+
{
143+
fullName:
144+
'before each fail with retry - first in test then in hook @beforeEachRetry test 08',
145+
message:
146+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
147+
name: 'test 08',
148+
status: 'unknown',
149+
},
150+
{
151+
fullName:
152+
'before each fail with retry - first in test then in hook @beforeEachRetry test 09',
153+
message:
154+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
155+
name: 'test 09',
156+
status: 'unknown',
157+
},
158+
{
159+
fullName:
160+
'before each fail with retry - first in test then in hook @beforeEachRetry test 10',
161+
message:
162+
'Fail in hook\n\nBecause this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `before each fail with retry...`',
163+
name: 'test 10',
164+
status: 'unknown',
165+
},
166+
]);
167+
});
168+
});
169+
});

0 commit comments

Comments
 (0)