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