Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
310 lines (232 loc) 路 8.73 KB
/
Copy pathtest.js
File metadata and controls
310 lines (232 loc) 路 8.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import test from '@ava/test';
import createChain from '../../lib/create-chain.js';
function createTestChain() {
const calls = [];
const chain = createChain((metadata, arguments_) => {
calls.push({metadata, arguments_});
}, {}, {});
return {calls, chain};
}
test('skipIf() keeps chaining methods available when condition is true', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.skipIf(true).serial('title', () => {});
});
t.is(calls.length, 1);
t.is(calls[0].metadata.serial, true);
t.is(calls[0].metadata.skipped, true);
});
test('skipIf() skips terminal .only chains', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.skipIf(true).only('title', () => {});
});
t.is(calls.length, 1);
t.is(calls[0].metadata.skipped, true);
t.is(calls[0].metadata.exclusive, undefined);
});
test('runIf() skips terminal .serial.only chains when condition is false', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.runIf(false).serial.only('title', () => {});
});
t.is(calls.length, 1);
t.is(calls[0].metadata.serial, true);
t.is(calls[0].metadata.skipped, true);
t.is(calls[0].metadata.exclusive, undefined);
});
test('skipIf() does not add conditional modifiers to terminal .only chains', t => {
const {chain} = createTestChain();
t.is(chain.skipIf(false).only.skipIf, undefined);
t.is(chain.skipIf(false).only.runIf, undefined);
});
test('skipIf() keeps .todo chaining available', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.skipIf(true).todo('title');
chain.skipIf(false).todo('title');
});
t.is(calls.length, 2);
t.is(calls[0].metadata.todo, true);
t.is(calls[1].metadata.todo, true);
});
test('skipIf(false) and runIf(true) behave as no-op for todo chains', t => {
const {calls, chain} = createTestChain();
chain.skipIf(false).todo('title');
chain.runIf(true).todo('title');
chain.serial.skipIf(false).todo('title');
chain.serial.runIf(true).todo('title');
t.is(calls.length, 4);
t.is(calls[0].metadata.skipped, undefined);
t.is(calls[1].metadata.skipped, undefined);
t.is(calls[2].metadata.skipped, undefined);
t.is(calls[3].metadata.skipped, undefined);
});
test('serial.skipIf() skips with serial flag preserved', t => {
const {calls, chain} = createTestChain();
chain.serial.skipIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.serial, true);
t.is(calls[0].metadata.skipped, true);
});
test('failing.skipIf() skips with failing flag preserved', t => {
const {calls, chain} = createTestChain();
chain.failing.skipIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.failing, true);
t.is(calls[0].metadata.skipped, true);
});
test('serial.failing.skipIf() skips with serial and failing flags preserved', t => {
const {calls, chain} = createTestChain();
chain.serial.failing.skipIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.serial, true);
t.is(calls[0].metadata.failing, true);
t.is(calls[0].metadata.skipped, true);
});
test('skipIf(true).todo() does not set skipped', t => {
const {calls, chain} = createTestChain();
chain.skipIf(true).todo('title');
t.is(calls.length, 1);
t.is(calls[0].metadata.todo, true);
t.is(calls[0].metadata.skipped, undefined);
});
test('conditional chains preserve hook access when skipped', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.skipIf(true).beforeEach('title', () => {});
chain.runIf(false).afterEach('title', () => {});
});
t.is(calls.length, 2);
t.is(calls[0].metadata.type, 'beforeEach');
t.is(calls[0].metadata.skipped, undefined);
t.is(calls[1].metadata.type, 'afterEach');
t.is(calls[1].metadata.skipped, undefined);
});
test('conditional chains preserve root macro and meta access when skipped', t => {
const {chain} = createTestChain();
const execFunction = () => {};
const titleFunction = provided => provided;
const objectMacro = {exec: execFunction, title: titleFunction};
const skippedFunctionMacro = chain.skipIf(true).macro(execFunction);
const runIfFunctionMacro = chain.runIf(false).macro(execFunction);
const skippedObjectMacro = chain.skipIf(true).macro(objectMacro);
const runIfObjectMacro = chain.runIf(false).macro(objectMacro);
t.is(typeof chain.skipIf(true).macro, 'function');
t.is(typeof chain.runIf(false).macro, 'function');
t.is(skippedFunctionMacro.exec, execFunction);
t.is(runIfFunctionMacro.exec, execFunction);
t.is(skippedObjectMacro.exec, execFunction);
t.is(skippedObjectMacro.title, titleFunction);
t.is(runIfObjectMacro.exec, execFunction);
t.is(runIfObjectMacro.title, titleFunction);
t.is(chain.skipIf(true).meta, chain.meta);
t.is(chain.runIf(false).meta, chain.meta);
});
test('skip state is irreversible: runIf(true) cannot undo a prior skipIf(true)', t => {
const {calls, chain} = createTestChain();
chain.skipIf(true).serial.runIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.serial, true);
t.is(calls[0].metadata.skipped, true);
});
test('accessing non-configurable accessor without getter on conditional chains returns undefined (proxy invariant)', t => {
const {chain} = createTestChain();
Object.defineProperty(chain, 'noGetter', {
configurable: false,
get: undefined,
set() {},
});
t.is(chain.skipIf(true).noGetter, undefined);
t.is(chain.skipIf(false).noGetter, undefined);
t.is(chain.runIf(false).noGetter, undefined);
t.is(chain.runIf(true).noGetter, undefined);
});
test('skipIf().skipIf() skips if either condition is true', t => {
const {calls, chain} = createTestChain();
chain.skipIf(true).skipIf(false)('title', () => {});
chain.skipIf(false).skipIf(true)('title', () => {});
t.is(calls.length, 2);
t.is(calls[0].metadata.skipped, true);
t.is(calls[1].metadata.skipped, true);
});
test('skipIf().skipIf() does not skip if both conditions are false', t => {
const {calls, chain} = createTestChain();
chain.skipIf(false).skipIf(false)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.skipped, undefined);
});
test('runIf().runIf() skips if either condition is false', t => {
const {calls, chain} = createTestChain();
chain.runIf(true).runIf(false)('title', () => {});
chain.runIf(false).runIf(true)('title', () => {});
t.is(calls.length, 2);
t.is(calls[0].metadata.skipped, true);
t.is(calls[1].metadata.skipped, true);
});
test('runIf().runIf() does not skip if both conditions are true', t => {
const {calls, chain} = createTestChain();
chain.runIf(true).runIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.skipped, undefined);
});
test('skipIf().runIf() skips if skipIf condition is true or runIf condition is false', t => {
const {calls, chain} = createTestChain();
chain.skipIf(true).runIf(true)('title', () => {}); // `skipIf` wins
chain.skipIf(false).runIf(false)('title', () => {}); // `runIf` wins
t.is(calls.length, 2);
t.is(calls[0].metadata.skipped, true);
t.is(calls[1].metadata.skipped, true);
});
test('skipIf(false).runIf(true) does not skip', t => {
const {calls, chain} = createTestChain();
chain.skipIf(false).runIf(true)('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.skipped, undefined);
});
test('cleanup() registers a cleanup task', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.cleanup('title', () => {});
chain.cleanup(() => {});
});
t.is(calls.length, 2);
t.is(calls[0].metadata.type, 'cleanup');
t.is(calls[1].metadata.type, 'cleanup');
});
test('cleanup.skip() skips the cleanup task', t => {
const {calls, chain} = createTestChain();
chain.cleanup.skip('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.type, 'cleanup');
t.is(calls[0].metadata.skipped, true);
});
test('cleanupEach() registers a cleanupEach task', t => {
const {calls, chain} = createTestChain();
t.notThrows(() => {
chain.cleanupEach('title', () => {});
chain.cleanupEach(() => {});
});
t.is(calls.length, 2);
t.is(calls[0].metadata.type, 'cleanupEach');
t.is(calls[1].metadata.type, 'cleanupEach');
});
test('serial.cleanup() preserves the serial flag', t => {
const {calls, chain} = createTestChain();
chain.serial.cleanup('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.type, 'cleanup');
t.is(calls[0].metadata.serial, true);
});
test('serial.cleanupEach() preserves the serial flag', t => {
const {calls, chain} = createTestChain();
chain.serial.cleanupEach('title', () => {});
t.is(calls.length, 1);
t.is(calls[0].metadata.type, 'cleanupEach');
t.is(calls[0].metadata.serial, true);
});
test('cleanup() and cleanupEach() are reachable from conditional chains', t => {
const {chain} = createTestChain();
t.is(typeof chain.skipIf(false).cleanup, 'function');
t.is(typeof chain.runIf(true).cleanupEach, 'function');
});