|
1 | | -import { expect, it, onTestFinished } from 'vitest' |
| 1 | +import { describe, expect, it, onTestFailed, onTestFinished } from 'vitest' |
2 | 2 |
|
3 | 3 | const collected: any[] = [] |
4 | 4 | const multiple: any[] = [] |
@@ -59,3 +59,141 @@ it('after', () => { |
59 | 59 | expect(collected).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) |
60 | 60 | expect(multiple).toEqual([4, 3, 2, 1]) |
61 | 61 | }) |
| 62 | + |
| 63 | +describe('repeats pass', () => { |
| 64 | + const state: string[] = [] |
| 65 | + |
| 66 | + it('run', { repeats: 2 }, (t) => { |
| 67 | + const tag = `(${t.task.result?.retryCount}, ${t.task.result?.repeatCount}) ` |
| 68 | + state.push(`${tag}run`) |
| 69 | + |
| 70 | + onTestFinished(() => { |
| 71 | + state.push(`${tag}finish`) |
| 72 | + }) |
| 73 | + |
| 74 | + onTestFailed(() => { |
| 75 | + state.push(`${tag}fail`) |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + it('assert', () => { |
| 80 | + expect(state).toMatchInlineSnapshot(` |
| 81 | + [ |
| 82 | + "(0, 0) run", |
| 83 | + "(0, 0) finish", |
| 84 | + "(0, 1) run", |
| 85 | + "(0, 1) finish", |
| 86 | + "(0, 2) run", |
| 87 | + "(0, 2) finish", |
| 88 | + ] |
| 89 | + `) |
| 90 | + }) |
| 91 | +}) |
| 92 | + |
| 93 | +describe('repeats fail', () => { |
| 94 | + const state: string[] = [] |
| 95 | + |
| 96 | + it.fails('run', { repeats: 2 }, (t) => { |
| 97 | + const tag = `(${t.task.result?.retryCount}, ${t.task.result?.repeatCount}) ` |
| 98 | + state.push(`${tag}run`) |
| 99 | + |
| 100 | + onTestFinished(() => { |
| 101 | + state.push(`${tag}finish`) |
| 102 | + }) |
| 103 | + |
| 104 | + onTestFailed(() => { |
| 105 | + state.push(`${tag}fail`) |
| 106 | + }) |
| 107 | + |
| 108 | + if (t.task.result?.repeatCount === 1) { |
| 109 | + throw new Error('fail') |
| 110 | + } |
| 111 | + }) |
| 112 | + |
| 113 | + it('assert', () => { |
| 114 | + expect(state).toMatchInlineSnapshot(` |
| 115 | + [ |
| 116 | + "(0, 0) run", |
| 117 | + "(0, 0) finish", |
| 118 | + "(0, 1) run", |
| 119 | + "(0, 1) finish", |
| 120 | + "(0, 1) fail", |
| 121 | + "(0, 2) run", |
| 122 | + "(0, 2) finish", |
| 123 | + "(0, 2) fail", |
| 124 | + ] |
| 125 | + `) |
| 126 | + }) |
| 127 | +}) |
| 128 | + |
| 129 | +describe('retry pass', () => { |
| 130 | + const state: string[] = [] |
| 131 | + |
| 132 | + it('run', { retry: 2 }, (t) => { |
| 133 | + const tag = `(${t.task.result?.retryCount}, ${t.task.result?.repeatCount}) ` |
| 134 | + state.push(`${tag}run`) |
| 135 | + |
| 136 | + onTestFinished(() => { |
| 137 | + state.push(`${tag}finish`) |
| 138 | + }) |
| 139 | + |
| 140 | + onTestFailed(() => { |
| 141 | + state.push(`${tag}fail`) |
| 142 | + }) |
| 143 | + |
| 144 | + if (t.task.result?.retryCount && t.task.result?.retryCount > 1) { |
| 145 | + return |
| 146 | + } |
| 147 | + throw new Error('fail') |
| 148 | + }) |
| 149 | + |
| 150 | + it('assert', () => { |
| 151 | + expect(state).toMatchInlineSnapshot(` |
| 152 | + [ |
| 153 | + "(0, 0) run", |
| 154 | + "(0, 0) finish", |
| 155 | + "(0, 0) fail", |
| 156 | + "(1, 0) run", |
| 157 | + "(1, 0) finish", |
| 158 | + "(1, 0) fail", |
| 159 | + "(2, 0) run", |
| 160 | + "(2, 0) finish", |
| 161 | + ] |
| 162 | + `) |
| 163 | + }) |
| 164 | +}) |
| 165 | + |
| 166 | +describe('retry fail', () => { |
| 167 | + const state: string[] = [] |
| 168 | + |
| 169 | + it.fails('run', { retry: 2 }, (t) => { |
| 170 | + const tag = `(${t.task.result?.retryCount}, ${t.task.result?.repeatCount}) ` |
| 171 | + state.push(`${tag}run`) |
| 172 | + |
| 173 | + onTestFinished(() => { |
| 174 | + state.push(`${tag}finish`) |
| 175 | + }) |
| 176 | + |
| 177 | + onTestFailed(() => { |
| 178 | + state.push(`${tag}fail`) |
| 179 | + }) |
| 180 | + |
| 181 | + throw new Error('fail') |
| 182 | + }) |
| 183 | + |
| 184 | + it('assert', () => { |
| 185 | + expect(state).toMatchInlineSnapshot(` |
| 186 | + [ |
| 187 | + "(0, 0) run", |
| 188 | + "(0, 0) finish", |
| 189 | + "(0, 0) fail", |
| 190 | + "(1, 0) run", |
| 191 | + "(1, 0) finish", |
| 192 | + "(1, 0) fail", |
| 193 | + "(2, 0) run", |
| 194 | + "(2, 0) finish", |
| 195 | + "(2, 0) fail", |
| 196 | + ] |
| 197 | + `) |
| 198 | + }) |
| 199 | +}) |
0 commit comments