2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

fix(fetch): optimize signals composing logic; (#6582)

This commit is contained in:
Dmitriy Mozgovoy
2024-08-30 21:26:12 +03:00
committed by GitHub
parent ee208cfcae
commit df9889b83c
4 changed files with 101 additions and 49 deletions
+43
View File
@@ -0,0 +1,43 @@
import assert from 'assert';
import composeSignals from '../../../lib/helpers/composeSignals.js';
describe('helpers::composeSignals', () => {
before(function () {
if (typeof AbortController !== 'function') {
this.skip();
}
});
it('should abort when any of the signals abort', () => {
let called;
const controllerA = new AbortController();
const controllerB = new AbortController();
const signal = composeSignals([controllerA.signal, controllerB.signal]);
signal.addEventListener('abort', () => {
called = true;
});
controllerA.abort(new Error('test'));
assert.ok(called);
});
it('should abort on timeout', async () => {
const signal = composeSignals([], 100);
await new Promise(resolve => {
signal.addEventListener('abort', resolve);
});
assert.match(String(signal.reason), /timeout 100 of ms exceeded/);
});
it('should return undefined if signals and timeout are not provided', async () => {
const signal = composeSignals([]);
assert.strictEqual(signal, undefined);
});
});