diff --git a/plugins/core/tests/extract.test.ts b/plugins/core/tests/extract.test.ts index b0c2ad4..10cf861 100644 --- a/plugins/core/tests/extract.test.ts +++ b/plugins/core/tests/extract.test.ts @@ -2,6 +2,7 @@ import { extractLinks } from '../src/crawler/extract.js'; import { test, expect, describe, vi, afterEach } from 'vitest'; import * as cheerio from 'cheerio'; +// Mock cheerio.load to allow us to simulate errors vi.mock('cheerio', async (importOriginal) => { const mod = await importOriginal(); return { @@ -50,4 +51,21 @@ describe('extractLinks', () => { error ); }); + + test('should handle non-Error exceptions gracefully', () => { + const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => { }); + const error = 'String error'; // Simulate a thrown string + + vi.mocked(cheerio.load).mockImplementationOnce(() => { + throw error; + }); + + const links = extractLinks('', 'https://example.com'); + + expect(links).toEqual([]); + expect(consoleSpy).toHaveBeenCalledWith( + expect.stringContaining('Error extracting links from https://example.com'), + error + ); + }); });