fix: request rewriter not functioning in transpiled code (#18948)
* fix: request rewriter not working in transpiled code * test: add app request-rewriter test case
This commit is contained in:
parent
8e15864469
commit
0fc3d5c1bc
|
|
@ -1,5 +1,3 @@
|
|||
import '@/utils/request-rewriter';
|
||||
|
||||
import { Hono } from 'hono';
|
||||
|
||||
import { compress } from 'hono/compress';
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import app from '@/app';
|
||||
import undici from 'undici';
|
||||
|
||||
const { config } = await import('@/config');
|
||||
|
||||
describe('index', () => {
|
||||
it('serve index', async () => {
|
||||
|
|
@ -9,3 +12,14 @@ describe('index', () => {
|
|||
expect(await res.text()).toContain('Welcome to RSSHub!');
|
||||
});
|
||||
});
|
||||
|
||||
describe('request-rewriter', () => {
|
||||
it('should rewrite request', async () => {
|
||||
const fetchSpy = vi.spyOn(undici, 'fetch');
|
||||
await app.request('/test/httperror');
|
||||
|
||||
// headers
|
||||
const headers: Headers = fetchSpy.mock.lastCall?.[0].headers;
|
||||
expect(headers.get('user-agent')).toBe(config.ua);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
// This file ensures that the request rewriter runs before the app
|
||||
|
||||
import '@/utils/request-rewriter';
|
||||
|
||||
export default (await import('./app-bootstrap')).default;
|
||||
Loading…
Reference in New Issue