Files
RSSHub/lib/errors/index.test.ts
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 65.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-09 00:08:15 +08:00

100 lines
4.2 KiB
TypeScript

import { load } from 'cheerio';
import { describe, expect, it } from 'vitest';
import app from '@/app';
import { config } from '@/config';
describe('error', () => {
it('error', async () => {
const response = await app.request('/test/error');
expect(response.status).toBe(503);
const text = await response.text();
expect(text).toMatch(/Error: Error test/);
});
});
describe('httperror', () => {
it('httperror', async () => {
const response = await app.request('/test/httperror');
expect(response.status).toBe(503);
const text = await response.text();
expect(text).toContain('FetchError: [GET] &quot;https://httpbingo.org/status/404&quot;: 404');
}, 20000);
});
describe('RequestInProgressError', () => {
it('RequestInProgressError with retry', async () => {
const responses = await Promise.all([app.request('/test/slow'), app.request('/test/slow')]);
expect(responses.map((r) => r.status)).toEqual([200, 200]);
});
it('RequestInProgressError', async () => {
const responses = await Promise.all([app.request('/test/slow4'), app.request('/test/slow4')]);
expect(new Set(responses.map((r) => r.status))).toEqual(new Set([200, 503]));
expect(new Set(responses.map((r) => r.headers.get('cache-control')))).toEqual(new Set([`public, max-age=${config.cache.routeExpire}`, `public, max-age=${config.requestTimeout / 1000}`]));
const texts = await Promise.all(responses.map((r) => r.text()));
expect(texts.filter((t) => t.includes('RequestInProgressError: This path is currently fetching, please come back later!'))).toHaveLength(1);
});
});
describe('config-not-found-error', () => {
it('config-not-found-error', async () => {
const response = await app.request('/test/config-not-found-error');
expect(response.status).toBe(503);
const text = await response.text();
expect(text).toMatch('ConfigNotFoundError: Test config not found error');
}, 20000);
});
describe('invalid-parameter-error', () => {
it('invalid-parameter-error', async () => {
const response = await app.request('/test/invalid-parameter-error');
expect(response.status).toBe(503);
const text = await response.text();
expect(text).toMatch('InvalidParameterError: Test invalid parameter error');
}, 20000);
});
describe('captcha-error', () => {
it('captcha-error', async () => {
const response = await app.request('/test/captcha-error');
expect(response.status).toBe(503);
const text = await response.text();
expect(text).toMatch('CaptchaError: Test captcha error');
}, 20000);
});
describe('route throws an error', () => {
it('route path error should have path mounted', async () => {
await app.request('/test/error');
await app.request('/thisDoesNotExist');
const response = await app.request('/');
const text = await response.text();
const $ = load(text);
$('.debug-item').each((_index, item) => {
const key = $(item).find('.debug-key').text().trim();
const value = $(item).find('.debug-value').html()?.trim();
switch (key) {
case 'Request Amount:':
expect(value).toBe('12');
break;
case 'Hot Routes:':
expect(value).toBe('9 /test/:id/:params?<br>');
break;
case 'Hot Paths:':
expect(value).toBe(
'2 /test/error<br>2 /test/slow<br>2 /test/slow4<br>1 /test/httperror<br>1 /test/config-not-found-error<br>1 /test/invalid-parameter-error<br>1 /test/captcha-error<br>1 /thisDoesNotExist<br>1 /<br>'
);
break;
case 'Hot Error Routes:':
expect(value).toBe('6 /test/:id/:params?<br>');
break;
case 'Hot Error Paths:':
expect(value).toBe('2 /test/error<br>1 /test/httperror<br>1 /test/slow4<br>1 /test/config-not-found-error<br>1 /test/invalid-parameter-error<br>1 /test/captcha-error<br>1 /thisDoesNotExist<br>');
break;
default:
}
});
});
});