From dd709bbc795cf6d8dd8dff208acc60b3ab76f5c1 Mon Sep 17 00:00:00 2001 From: Mazen Ramadan Date: Wed, 22 May 2024 18:02:00 +0300 Subject: [PATCH] update scrapeConfig tests and remove default format api param --- __tests__/scrapeconfig.test.ts | 26 ++++++++++++++++++++++++++ src/scrapeconfig.ts | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/__tests__/scrapeconfig.test.ts b/__tests__/scrapeconfig.test.ts index f7e63cc..4c179ed 100644 --- a/__tests__/scrapeconfig.test.ts +++ b/__tests__/scrapeconfig.test.ts @@ -194,6 +194,21 @@ describe('url param generation', () => { 'screenshots[everything]': 'fullpage', }); }); + it('screenshot flags converted to params', () => { + const config = new ScrapeConfig({ + url: 'http://httpbin.dev/get', + screenshots: { everything: 'fullpage' }, + screenshot_flags: "load_images,dark_mode,block_banners,high_quality,print_media_format", + render_js: true, + }); + expect(config.toApiParams({ key: '1234' })).toEqual({ + key: '1234', + url: 'http://httpbin.dev/get', + 'screenshots[everything]': 'fullpage', + screenshot_flags: "load_images,dark_mode,block_banners,high_quality,print_media_format", + render_js: true, + }); + }); it('asp enables', () => { const config = new ScrapeConfig({ url: 'http://httpbin.dev/get', @@ -238,6 +253,17 @@ describe('url param generation', () => { tags: 'foo,bar,gaz', }); }); + it('format set', () => { + const config = new ScrapeConfig({ + url: 'http://httpbin.dev/get', + format: "markdown", + }); + expect(config.toApiParams({ key: '1234' })).toEqual({ + key: '1234', + url: 'http://httpbin.dev/get', + format: "markdown", + }); + }); it('debug sets', () => { const config = new ScrapeConfig({ url: 'http://httpbin.dev/get', diff --git a/src/scrapeconfig.ts b/src/scrapeconfig.ts index 26bdf8d..f1237f4 100644 --- a/src/scrapeconfig.ts +++ b/src/scrapeconfig.ts @@ -24,7 +24,7 @@ export class ScrapeConfig { proxy_pool?: string = null; session?: string = null; tags: Set = new Set(); - format?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw' = 'raw'; //unchanged + format?: string = null; // raw(unchanged) correlation_id?: string = null; cookies?: Rec = null; body?: string = null; @@ -62,7 +62,7 @@ export class ScrapeConfig { proxy_pool?: string; session?: string; tags?: Array; - format?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw'; + format?: string; correlation_id?: string; cookies?: Rec; body?: string;