chore(deps-dev): bump msw from 2.4.3 to 2.12.14 (#21483)
* chore(deps-dev): bump msw from 2.4.3 to 2.12.14 Bumps [msw](https://github.com/mswjs/msw) from 2.4.3 to 2.12.14. - [Release notes](https://github.com/mswjs/msw/releases) - [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md) - [Commits](https://github.com/mswjs/msw/compare/v2.4.3...v2.12.14) --- updated-dependencies: - dependency-name: msw dependency-version: 2.12.14 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore: remove supertest MSW's setupServer() works by patching Node's http module (via @mswjs/interceptors) to intercept outgoing requests. supertest's requests to http://127.0.0.1:1200 go through the same patched http module which causes server bad request * chore(patch): add patch for @mswjs/interceptors@0.41.3 * fix(server): update server listen options to bypass unhandled requests * chore: update patch for @mswjs/interceptors --------- 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>
This commit is contained in:
+28
-28
@@ -1,77 +1,77 @@
|
||||
import { load } from 'cheerio';
|
||||
import supertest from 'supertest';
|
||||
import { afterAll, describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import app from '@/app';
|
||||
import { config } from '@/config';
|
||||
import server from '@/index';
|
||||
|
||||
const request = supertest(server);
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
describe('error', () => {
|
||||
it(`error`, async () => {
|
||||
const response = await request.get('/test/error');
|
||||
const response = await app.request('/test/error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch(/Error: Error test/);
|
||||
const text = await response.text();
|
||||
expect(text).toMatch(/Error: Error test/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('httperror', () => {
|
||||
it(`httperror`, async () => {
|
||||
const response = await request.get('/test/httperror');
|
||||
const response = await app.request('/test/httperror');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toContain('FetchError: [GET] "https://httpbingo.org/status/404": 404 Not Found');
|
||||
const text = await response.text();
|
||||
expect(text).toContain('FetchError: [GET] "https://httpbingo.org/status/404": 404 Not Found');
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
describe('RequestInProgressError', () => {
|
||||
it(`RequestInProgressError with retry`, async () => {
|
||||
const responses = await Promise.all([request.get('/test/slow'), request.get('/test/slow')]);
|
||||
const responses = await Promise.all([app.request('/test/slow'), app.request('/test/slow')]);
|
||||
expect(new Set(responses.map((r) => r.status))).toEqual(new Set([200, 200]));
|
||||
});
|
||||
it(`RequestInProgressError`, async () => {
|
||||
const responses = await Promise.all([request.get('/test/slow4'), request.get('/test/slow4')]);
|
||||
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['cache-control']))).toEqual(new Set([`public, max-age=${config.cache.routeExpire}`, `public, max-age=${config.requestTimeout / 1000}`]));
|
||||
expect(responses.filter((r) => r.text.includes('RequestInProgressError: This path is currently fetching, please come back later!'))).toHaveLength(1);
|
||||
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 request.get('/test/config-not-found-error');
|
||||
const response = await app.request('/test/config-not-found-error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch('ConfigNotFoundError: Test config not found error');
|
||||
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 request.get('/test/invalid-parameter-error');
|
||||
const response = await app.request('/test/invalid-parameter-error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch('InvalidParameterError: Test invalid parameter error');
|
||||
const text = await response.text();
|
||||
expect(text).toMatch('InvalidParameterError: Test invalid parameter error');
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
describe('captcha-error', () => {
|
||||
it(`captcha-error`, async () => {
|
||||
const response = await request.get('/test/captcha-error');
|
||||
const response = await app.request('/test/captcha-error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch('CaptchaError: Test captcha error');
|
||||
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 request.get('/test/error');
|
||||
await request.get('/thisDoesNotExist');
|
||||
const response = await request.get('/');
|
||||
await app.request('/test/error');
|
||||
await app.request('/thisDoesNotExist');
|
||||
const response = await app.request('/');
|
||||
|
||||
const $ = load(response.text);
|
||||
$('.debug-item').each((index, item) => {
|
||||
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) {
|
||||
|
||||
+7
-2
@@ -202,7 +202,12 @@ var ct = "${1_636_626_300}";
|
||||
)
|
||||
),
|
||||
http.get(`https://mp.weixin.qq.com/s/rsshub_test`, () => HttpResponse.redirect(`https://mp.weixin.qq.com/rsshub_test/fallback`)),
|
||||
http.get(`https://mp.weixin.qq.com/s?__biz=rsshub_test&mid=1&idx=1&sn=1`, () => HttpResponse.redirect(`https://mp.weixin.qq.com/rsshub_test/fallback`)),
|
||||
http.get(`https://mp.weixin.qq.com/s`, ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
if (url.searchParams.get('__biz') === 'rsshub_test' && url.searchParams.get('mid') === '1' && url.searchParams.get('idx') === '1' && url.searchParams.get('sn') === '1') {
|
||||
return HttpResponse.redirect(`https://mp.weixin.qq.com/rsshub_test/fallback`);
|
||||
}
|
||||
}),
|
||||
http.get(`https://mp.weixin.qq.com/mp/rsshub_test/waf`, () =>
|
||||
HttpResponse.text(
|
||||
`<html>
|
||||
@@ -284,7 +289,7 @@ Unknown paragraph
|
||||
}),
|
||||
http.get(`http://rsshub.test/rss`, () => HttpResponse.text('<rss version="2.0"><channel><item></item></channel></rss>'))
|
||||
);
|
||||
server.listen();
|
||||
server.listen({ onUnhandledRequest: 'bypass' });
|
||||
|
||||
afterAll(() => server.close());
|
||||
afterEach(() => server.resetHandlers());
|
||||
|
||||
@@ -568,15 +568,17 @@ class PageParsers {
|
||||
}
|
||||
|
||||
const redirectHelper = async (url: string, maxRedirects: number = 5) => {
|
||||
maxRedirects--;
|
||||
const raw = await ofetch.raw(url);
|
||||
const raw = await ofetch.raw(url, {
|
||||
redirect: 'manual',
|
||||
});
|
||||
if ([301, 302, 303, 307, 308].includes(raw.status)) {
|
||||
if (!raw.headers.has('location')) {
|
||||
const location = raw.headers.get('location');
|
||||
if (!location) {
|
||||
error('redirect without location', url);
|
||||
} else if (maxRedirects <= 0) {
|
||||
} else if (maxRedirects <= 1) {
|
||||
error('too many redirects', url);
|
||||
}
|
||||
return await redirectHelper(raw.headers.get('location') as string, maxRedirects);
|
||||
return await redirectHelper(new URL(location, url).toString(), maxRedirects - 1);
|
||||
}
|
||||
return raw;
|
||||
};
|
||||
|
||||
@@ -169,7 +169,6 @@
|
||||
"@types/module-alias": "2.0.4",
|
||||
"@types/node": "25.5.0",
|
||||
"@types/sanitize-html": "2.16.1",
|
||||
"@types/supertest": "7.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "8.57.2",
|
||||
"@typescript-eslint/parser": "8.57.2",
|
||||
"@vercel/nft": "1.5.0",
|
||||
@@ -191,13 +190,12 @@
|
||||
"lint-staged": "16.4.0",
|
||||
|
||||
Reference in New Issue
Block a user