File size: 1,437 Bytes
bf48b89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { afterEach, describe, expect, it, vi } from 'vitest';
const errorSpy = vi.fn();
const infoSpy = vi.fn();
const ofetchMock = vi.fn();
const setupMocks = () => {
vi.resetModules();
vi.doMock('@/utils/logger', () => ({
default: {
error: errorSpy,
info: infoSpy,
},
}));
vi.doMock('ofetch', () => ({
ofetch: ofetchMock,
}));
};
afterEach(() => {
vi.clearAllMocks();
vi.unmock('@/utils/logger');
vi.unmock('ofetch');
ofetchMock.mockReset();
});
describe('config remote errors', () => {
it('logs when remote config returns empty', async () => {
process.env.REMOTE_CONFIG = 'http://rsshub.test/empty';
setupMocks();
ofetchMock.mockResolvedValueOnce(null);
await import('@/config');
await vi.waitFor(() => {
expect(errorSpy).toHaveBeenCalledWith('Remote config load failed.');
});
delete process.env.REMOTE_CONFIG;
});
it('logs when remote config throws', async () => {
process.env.REMOTE_CONFIG = 'http://rsshub.test/fail';
const error = new Error('boom');
setupMocks();
ofetchMock.mockRejectedValueOnce(error);
await import('@/config');
await vi.waitFor(() => {
expect(errorSpy).toHaveBeenCalledWith('Remote config load failed.', error);
});
delete process.env.REMOTE_CONFIG;
});
});
|