Files
hls.js/tests/unit/utils/error-helper.js
82a2589574 Custom shouldRetry in retryConfig (follow up) (#5762)
* Custom shoudRetry in retryConfig (#5658)

Co-authored-by: pfomin <pfomin@ivi.ru>

* Replace httpStatus argument with LoaderResponse in config.shouldRetry #5658

---------

Co-authored-by: Pavel Fomin <me@pavelfomin.ru>
Co-authored-by: pfomin <pfomin@ivi.ru>
2023-08-31 10:27:26 -07:00

82 lines
1.5 KiB
JavaScript

import { shouldRetry } from '../../../src/utils/error-helper';
describe('ErrorHelper', function () {
it('shouldRetry', function () {
const retryConfig = {
maxNumRetry: 3,
};
expect(
shouldRetry(retryConfig, 3, false, {
url: '',
data: undefined,
code: 502,
}),
).to.be.false;
expect(
shouldRetry(null, 3, false, {
url: '',
data: undefined,
code: 502,
}),
).to.be.false;
expect(
shouldRetry(retryConfig, 2, false, {
url: '',
data: undefined,
code: 502,
}),
).to.be.true;
expect(
shouldRetry(retryConfig, 2, false, {
url: '',
data: undefined,
code: 404,
}),
).to.be.false;
retryConfig.shouldRetry = (
_retryConfig,
_retryCount,
_isTimeout,
loaderResponse,
retry,
) => {
if (!retry && loaderResponse?.code === 404) {
return true;
}
return false;
};
expect(
shouldRetry(
retryConfig,
5,
false,
{
url: '',
data: undefined,
code: 404,
},
false,
),
).to.be.true;
retryConfig.shouldRetry = (retryConfig, retryCount) => {
return retryConfig.maxNumRetry <= retryCount;
};
expect(
shouldRetry(
retryConfig,
2,
false,
{
url: '',
data: undefined,
code: 502,
},
true,
),
).to.be.false;
});
});