Files
RSSHub/lib/middleware/cache-error.test.ts
T
Tony cb0791cb41 perf: dx (#22478)
* perf: use only one WASM alloc for xxhash

* perf(deps): lazy load mercury-parser and use googleapis/youtube instead of heavy googleapis

* perf(dx): lazy load dev registry

speed up npm dev script

* perf: close playwright browser on destroy

* fix: show exception msg in prod

* revert: "perf: use only one WASM alloc for xxhash"

This reverts commit 01ecdd48d0.

* perf: use only one WASM alloc for xxhash

* test: add claim for worker

* fix: missing piece from 8dd9c9a

* feat: add namespace to the chunkfilename

* fix: keep var naming
2026-07-09 02:37:41 +08:00

51 lines
1.2 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
const setSpy = vi.fn(() => null);
const getSpy = vi.fn(() => null);
vi.mock('xxhash-wasm', () => ({
default: () =>
Promise.resolve({
h64ToString: () => 'hash',
}),
}));
vi.mock('@/utils/cache/index', () => ({
default: {
status: { available: true },
globalCache: {
get: getSpy,
set: setSpy,
claim: vi.fn(() => true),
},
},
}));
describe('cache middleware', () => {
it('clears control key when downstream throws', async () => {
const { default: cacheMiddleware } = await import('@/middleware/cache');
const ctx = {
req: {
path: '/test',
query: () => null,
},
res: {
headers: new Headers(),
},
status: vi.fn(),
header: vi.fn(),
set: vi.fn(),
get: vi.fn(),
};
await expect(
cacheMiddleware(ctx as any, () => {
throw new Error('boom');
})
).rejects.toThrow('boom');
expect(setSpy.mock.calls.some(([, value]) => value === '0')).toBe(true);
});
});