Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

1.2 KB
Raw Blame
import { GotScrapingHttpClient } from '@crawlee/got-scraping-client';
import { gotScraping } from 'got-scraping';

vi.mock('got-scraping', () => ({
    gotScraping: vi.fn(async () => ({
        rawBody: Buffer.from('ok'),
        headers: { 'content-type': 'text/plain' },
        statusCode: 200,
        statusMessage: 'OK',
        url: 'http://example.com/',
    })),
}));

describe('GotScrapingHttpClient', () => {
    beforeEach(() => {
        vi.mocked(gotScraping).mockClear();
    });

    test('disables certificate verification when ignoreTlsErrors is set', async () => {
        const httpClient = new GotScrapingHttpClient();

        await httpClient.sendRequest(new Request('http://example.com'), { ignoreTlsErrors: true });

        expect(gotScraping).toHaveBeenCalledWith(expect.objectContaining({ https: { rejectUnauthorized: false } }));
    });

    test('leaves certificate verification enabled without the flag', async () => {
        const httpClient = new GotScrapingHttpClient();

        await httpClient.sendRequest(new Request('http://example.com'));

        expect(gotScraping).toHaveBeenCalledWith(expect.not.objectContaining({ https: expect.anything() }));
    });
});