Skip to content

Commit cda645b

Browse files
committed
wip
1 parent 6c9fe3c commit cda645b

6 files changed

Lines changed: 45 additions & 46 deletions

File tree

src/AbortError.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,41 @@ it('catchAbortError', () => {
3535
expect(() => catchAbortError(new Error())).toThrow();
3636
});
3737

38-
test('AbortError with custom message', () => {
38+
it('AbortError with custom message', () => {
3939
const error = new AbortError('Custom abort message');
4040
expect(error.message).toBe('Custom abort message');
4141
expect(error.name).toBe('AbortError');
4242
});
4343

44-
test('AbortError default message', () => {
44+
it('AbortError default message', () => {
4545
const error = new AbortError();
4646
expect(error.message).toBe('The operation has been aborted');
4747
expect(error.name).toBe('AbortError');
4848
});
4949

50-
test('AbortError with captureStackTrace disabled', () => {
50+
it('AbortError with captureStackTrace disabled', () => {
5151
const error = new AbortError('Test message', false);
5252
expect(error.message).toBe('Test message');
5353
expect(error.name).toBe('AbortError');
54-
expect(error.stack).toBe(undefined);
54+
expect(error.stack).toBe('');
5555

5656
expect(isAbortError(error)).toBe(true);
5757
expect(error).toBeInstanceOf(Error);
5858
expect(error).toBeInstanceOf(AbortError);
5959
});
6060

61-
test('AbortError with captureStackTrace enabled', () => {
61+
it('AbortError with captureStackTrace enabled', () => {
6262
const error = new AbortError('Test message', true);
6363
expect(error.message).toBe('Test message');
6464
expect(error.name).toBe('AbortError');
65-
expect(error.stack).toContain('AbortError: Test message');
6665
expect(error.stack).toContain('src/AbortError.test.ts');
6766

6867
expect(isAbortError(error)).toBe(true);
6968
expect(error).toBeInstanceOf(Error);
7069
expect(error).toBeInstanceOf(AbortError);
7170
});
7271

73-
test('throwIfAborted with custom reason', () => {
72+
it('throwIfAborted with custom reason', () => {
7473
const abortController = new AbortController();
7574
const customReason = new Error('Custom reason');
7675
abortController.abort(customReason);

src/AbortError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
export class AbortError implements Error {
88
name: 'AbortError' = 'AbortError';
9-
stack?: string;
9+
stack: string = '';
1010

1111
constructor(
1212
public message = 'The operation has been aborted',

src/all.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import defer from 'defer-promise';
22
import expect from 'expect';
33
import {AbortError} from './AbortError';
44
import {all} from './all';
5-
import {spyOn} from './testUtils/spy';
5+
import {createSpy, spyOn} from './testUtils/spy';
66
import {nextTick} from './utils/nextTick';
77

88
it('external abort', async () => {
@@ -209,7 +209,7 @@ it('empty', async () => {
209209
expect(removeEventListenerSpy.callCount).toBe(0);
210210
});
211211

212-
test('abort with custom reason', async () => {
212+
it('abort with custom reason', async () => {
213213
const abortController = new AbortController();
214214
const signal = abortController.signal;
215215

@@ -240,21 +240,21 @@ test('abort with custom reason', async () => {
240240
});
241241
});
242242

243-
test('abort before all with custom reason', async () => {
243+
it('abort before all with custom reason', async () => {
244244
const abortController = new AbortController();
245245
const signal = abortController.signal;
246246

247247
const customReason = new Error('Custom abort reason');
248248
abortController.abort(customReason);
249249

250-
const executor = jest.fn((signal: AbortSignal) => [Promise.resolve('test')]);
250+
const executor = createSpy((signal: AbortSignal) => [Promise.resolve('test')]);
251251

252252
await expect(all(signal, executor)).rejects.toBe(customReason);
253253

254-
expect(executor).not.toHaveBeenCalled();
254+
expect(executor.callCount).toBe(0);
255255
});
256256

257-
test('innerSignal receives custom reason on external abort', async () => {
257+
it('innerSignal receives custom reason on external abort', async () => {
258258
const abortController = new AbortController();
259259
const signal = abortController.signal;
260260

@@ -275,7 +275,7 @@ test('innerSignal receives custom reason on external abort', async () => {
275275
expect(innerSignal!.reason).toBe(customReason);
276276
});
277277

278-
test('innerSignal receives descriptive reason on promise rejection', async () => {
278+
it('innerSignal receives descriptive reason on promise rejection', async () => {
279279
const abortController = new AbortController();
280280
const signal = abortController.signal;
281281

src/execute.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ it('resolve immediately', async () => {
3434

3535
it('resolve before abort', async () => {
3636
const abortController = new AbortController();
37-
const signal = abortController.signal;
37+
const signal = abortController.signal;
3838
const addEventListenerSpy = spyOn(signal, 'addEventListener');
3939
const removeEventListenerSpy = spyOn(signal, 'removeEventListener');
4040

@@ -320,12 +320,12 @@ it('async abort callback rejection', async () => {
320320
expect(removeEventListenerSpy.callCount).toBe(1);
321321
});
322322

323-
test('abort with custom reason', async () => {
323+
it('abort with custom reason', async () => {
324324
const abortController = new AbortController();
325325
const signal = abortController.signal;
326326

327327
const customReason = new Error('Custom abort reason');
328-
const callback = jest.fn((reason?: unknown) => {
328+
const callback = createSpy((reason?: unknown) => {
329329
expect(reason).toBe(customReason);
330330
});
331331

@@ -346,21 +346,21 @@ test('abort with custom reason', async () => {
346346

347347
await nextTick();
348348

349-
expect(callback).toHaveBeenCalledTimes(1);
349+
expect(callback.callCount).toBe(1);
350350
expect(result).toMatchObject({
351351
status: 'rejected',
352352
reason: customReason,
353353
});
354354
});
355355

356-
test('abort before execute with custom reason', async () => {
356+
it('abort before execute with custom reason', async () => {
357357
const abortController = new AbortController();
358358
const signal = abortController.signal;
359359

360360
const customReason = new Error('Custom abort reason');
361361
abortController.abort(customReason);
362362

363-
const executor = jest.fn(
363+
const executor = createSpy(
364364
(
365365
resolve: (value: string) => void,
366366
reject: (reason?: any) => void,
@@ -371,17 +371,17 @@ test('abort before execute with custom reason', async () => {
371371

372372
await expect(execute(signal, executor)).rejects.toBe(customReason);
373373

374-
expect(executor).not.toHaveBeenCalled();
374+
expect(executor.callCount).toBe(0);
375375
});
376376

377-
test('async abort callback with custom reason', async () => {
377+
it('async abort callback with custom reason', async () => {
378378
const abortController = new AbortController();
379379
const signal = abortController.signal;
380380

381381
const customReason = new Error('Custom abort reason');
382382
const callbackDeferred = defer<void>();
383383

384-
const callback = jest.fn((reason?: unknown) => {
384+
const callback = createSpy((reason?: unknown) => {
385385
expect(reason).toBe(customReason);
386386
return callbackDeferred.promise;
387387
});
@@ -413,5 +413,5 @@ test('async abort callback with custom reason', async () => {
413413
status: 'rejected',
414414
reason: customReason,
415415
});
416-
expect(callback).toHaveBeenCalledTimes(1);
416+
expect(callback.callCount).toBe(1);
417417
});

src/race.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import defer from 'defer-promise';
22
import expect from 'expect';
33
import {AbortError} from './AbortError';
44
import {race} from './race';
5-
import {spyOn} from './testUtils/spy';
5+
import {createSpy, spyOn} from './testUtils/spy';
66
import {nextTick} from './utils/nextTick';
77

88
it('external abort', async () => {
@@ -197,7 +197,7 @@ it('reject during cleanup', async () => {
197197
expect(removeEventListenerSpy.callCount).toBe(1);
198198
});
199199

200-
test('abort with custom reason', async () => {
200+
it('abort with custom reason', async () => {
201201
const abortController = new AbortController();
202202
const signal = abortController.signal;
203203

@@ -228,21 +228,21 @@ test('abort with custom reason', async () => {
228228
});
229229
});
230230

231-
test('abort before race with custom reason', async () => {
231+
it('abort before race with custom reason', async () => {
232232
const abortController = new AbortController();
233233
const signal = abortController.signal;
234234

235235
const customReason = new Error('Custom abort reason');
236236
abortController.abort(customReason);
237237

238-
const executor = jest.fn((signal: AbortSignal) => [Promise.resolve('test')]);
238+
const executor = createSpy((signal: AbortSignal) => [Promise.resolve('test')]);
239239

240240
await expect(race(signal, executor)).rejects.toBe(customReason);
241241

242-
expect(executor).not.toHaveBeenCalled();
242+
expect(executor.callCount).toBe(0);
243243
});
244244

245-
test('innerSignal receives custom reason on external abort', async () => {
245+
it('innerSignal receives custom reason on external abort', async () => {
246246
const abortController = new AbortController();
247247
const signal = abortController.signal;
248248

@@ -263,7 +263,7 @@ test('innerSignal receives custom reason on external abort', async () => {
263263
expect(innerSignal!.reason).toBe(customReason);
264264
});
265265

266-
test('innerSignal receives descriptive reason on promise settlement', async () => {
266+
it('innerSignal receives descriptive reason on promise settlement', async () => {
267267
const abortController = new AbortController();
268268
const signal = abortController.signal;
269269

src/spawn.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ it('fork manual abort', async () => {
1818
try {
1919
await forever(signal);
2020
} catch (err: any) {
21-
actions.push(`fork abort: ${err.message}`);
21+
actions.push('fork abort');
2222
}
2323
});
2424

@@ -34,7 +34,7 @@ it('fork manual abort', async () => {
3434
'fork start',
3535
'post fork',
3636
'pre task abort',
37-
'fork abort: The operation has been aborted',
37+
'fork abort',
3838
'post task abort',
3939
]);
4040

@@ -56,7 +56,7 @@ it('fork abort on spawn finish', async () => {
5656
try {
5757
await forever(signal);
5858
} catch (err: any) {
59-
actions.push(`fork abort: ${err.message}`);
59+
actions.push('fork abort');
6060
}
6161
});
6262

@@ -69,7 +69,7 @@ it('fork abort on spawn finish', async () => {
6969
'fork start',
7070
'post fork',
7171
'spawn finish',
72-
'fork abort: The operation has been aborted',
72+
'fork abort',
7373
]);
7474

7575
expect(addEventListenerSpy.callCount).toBe(1);
@@ -90,7 +90,7 @@ it('fork abort on spawn error', async () => {
9090
try {
9191
await forever(signal);
9292
} catch (err: any) {
93-
actions.push(`fork abort: ${err.message}`);
93+
actions.push('fork abort');
9494
}
9595
});
9696

@@ -106,7 +106,7 @@ it('fork abort on spawn error', async () => {
106106
'fork start',
107107
'post fork',
108108
'spawn finish',
109-
'fork abort: The operation has been aborted',
109+
'fork abort',
110110
'spawn throw: the-error',
111111
]);
112112

@@ -135,7 +135,7 @@ it('error thrown from fork', async () => {
135135
try {
136136
await forever(signal);
137137
} catch (err: any) {
138-
actions.push(`spawn abort: ${err.message}`);
138+
actions.push('spawn abort');
139139
throw err;
140140
}
141141
}).catch(err => {
@@ -146,7 +146,7 @@ it('error thrown from fork', async () => {
146146
'fork start',
147147
'post fork',
148148
'fork finish',
149-
'spawn abort: The operation has been aborted',
149+
'spawn abort',
150150
'spawn throw: the-error',
151151
]);
152152

@@ -190,7 +190,7 @@ it('abort before spawn', async () => {
190190
expect(removeEventListenerSpy.callCount).toBe(0);
191191
});
192192

193-
test('abort with custom reason during spawn execution', async () => {
193+
it('abort with custom reason during spawn execution', async () => {
194194
const abortController = new AbortController();
195195
const signal = abortController.signal;
196196

@@ -203,7 +203,7 @@ test('abort with custom reason during spawn execution', async () => {
203203
try {
204204
await forever(signal);
205205
} catch (err: any) {
206-
actions.push(`fork abort: ${err.message}`);
206+
actions.push('fork abort');
207207
}
208208
});
209209

@@ -219,10 +219,10 @@ test('abort with custom reason during spawn execution', async () => {
219219
expect(actions).toContain('fork start');
220220
expect(actions).toContain('post fork');
221221
expect(actions).toContain('pre abort');
222-
expect(actions).toContain('fork abort: The operation has been aborted');
222+
expect(actions).toContain('fork abort');
223223
});
224224

225-
test('innerSignal aborted on spawn finish', async () => {
225+
it('innerSignal aborted on spawn finish', async () => {
226226
const abortController = new AbortController();
227227
const signal = abortController.signal;
228228

@@ -240,7 +240,7 @@ test('innerSignal aborted on spawn finish', async () => {
240240
expect(innerSignal!.aborted).toBe(true);
241241
});
242242

243-
test('innerSignal aborted on fork error', async () => {
243+
it('innerSignal aborted on fork error', async () => {
244244
const abortController = new AbortController();
245245
const signal = abortController.signal;
246246

@@ -259,7 +259,7 @@ test('innerSignal aborted on fork error', async () => {
259259
expect(innerSignal!.aborted).toBe(true);
260260
});
261261

262-
test('innerSignal aborted when spawn function throws', async () => {
262+
it('innerSignal aborted when spawn function throws', async () => {
263263
const abortController = new AbortController();
264264
const signal = abortController.signal;
265265

0 commit comments

Comments
 (0)