@@ -4,6 +4,7 @@ import { ScrapeConfig } from '../../src/scrapeconfig.ts';
4
4
import { log } from '../../src/logger.ts' ;
5
5
import { assertEquals , assertRejects } from "https://deno.land/[email protected] /assert/mod.ts" ;
6
6
import { resultFactory , responseFactory } from '../utils.ts' ;
7
+ import type { RequestOptions } from '../../src/utils.ts' ;
7
8
import { stub } from "https://deno.land/std/testing/mock.ts" ;
8
9
9
10
log . setLevel ( 'DEBUG' ) ;
@@ -12,7 +13,7 @@ Deno.test('scrape: GET success', async () => {
12
13
const KEY = '__API_KEY__' ;
13
14
const client = new ScrapflyClient ( { key : KEY } ) ;
14
15
15
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
16
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
16
17
const configUrl = new URL ( config . url ) ;
17
18
assertEquals ( configUrl . origin + configUrl . pathname , client . HOST + '/scrape' ) ;
18
19
assertEquals ( config . method , 'GET' ) ;
@@ -42,7 +43,7 @@ Deno.test('scrape errors: raises ApiHttpServerError on 500 and success', async (
42
43
const KEY = '__API_KEY__' ;
43
44
const client = new ScrapflyClient ( { key : KEY } ) ;
44
45
45
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
46
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
46
47
const result = resultFactory ( {
47
48
url : 'https://httpbin.dev/json' ,
48
49
status_code : 500 ,
@@ -71,7 +72,7 @@ Deno.test('scrape errors: raises BadApiKeyError on 401', async () => {
71
72
const KEY = '__API_KEY__' ;
72
73
const client = new ScrapflyClient ( { key : KEY } ) ;
73
74
74
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
75
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
75
76
const result = {
76
77
status : 'error' ,
77
78
http_code : 401 ,
@@ -100,7 +101,7 @@ Deno.test('scrape errors: raises TooManyRequests on 429 and success', async () =
100
101
const KEY = '__API_KEY__' ;
101
102
const client = new ScrapflyClient ( { key : KEY } ) ;
102
103
103
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
104
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
104
105
const result = resultFactory ( {
105
106
url : 'https://httpbin.dev/json' ,
106
107
status_code : 429 ,
@@ -128,7 +129,7 @@ Deno.test('scrape errors: raises ScrapflyScrapeError on ::SCRAPE:: resource and
128
129
const KEY = '__API_KEY__' ;
129
130
const client = new ScrapflyClient ( { key : KEY } ) ;
130
131
131
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
132
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
132
133
const result = resultFactory ( {
133
134
url : config . url ,
134
135
status : 'ERR::SCRAPE::BAD_PROTOCOL' ,
@@ -155,7 +156,7 @@ Deno.test('scrape errors: raises ScrapflyWebhookError on ::WEBHOOK:: resource an
155
156
const KEY = '__API_KEY__' ;
156
157
const client = new ScrapflyClient ( { key : KEY } ) ;
157
158
158
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
159
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
159
160
const result = resultFactory ( {
160
161
url : config . url ,
161
162
status : 'ERR::WEBHOOK::DISABLED ' ,
@@ -182,7 +183,7 @@ Deno.test('scrape errors: raises ScrapflyProxyError on ERR::PROXY::POOL_NOT_FOUN
182
183
const KEY = '__API_KEY__' ;
183
184
const client = new ScrapflyClient ( { key : KEY } ) ;
184
185
185
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
186
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
186
187
const result = resultFactory ( {
187
188
url : config . url ,
188
189
status : 'ERR::PROXY::POOL_NOT_FOUND ' ,
@@ -209,7 +210,7 @@ Deno.test('scrape errors: raises ScrapflyScheduleError on ERR::SCHEDULE::DISABLE
209
210
const KEY = '__API_KEY__' ;
210
211
const client = new ScrapflyClient ( { key : KEY } ) ;
211
212
212
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
213
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
213
214
const result = resultFactory ( {
214
215
url : config . url ,
215
216
status : 'ERR::SCHEDULE::DISABLED' ,
@@ -236,7 +237,7 @@ Deno.test('scrape errors: raises ScrapflyAspError on ERR::ASP::SHIELD_ERROR reso
236
237
const KEY = '__API_KEY__' ;
237
238
const client = new ScrapflyClient ( { key : KEY } ) ;
238
239
239
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
240
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
240
241
const result = resultFactory ( {
241
242
url : config . url ,
242
243
status : 'ERR::ASP::SHIELD_ERROR' ,
@@ -263,7 +264,7 @@ Deno.test('scrape errors: raises ScrapflySessionError on ERR::SESSION::CONCURREN
263
264
const KEY = '__API_KEY__' ;
264
265
const client = new ScrapflyClient ( { key : KEY } ) ;
265
266
266
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
267
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
267
268
const result = resultFactory ( {
268
269
url : config . url ,
269
270
status : 'ERR::SESSION::CONCURRENT_ACCESS' ,
@@ -290,7 +291,7 @@ Deno.test('scrape errors: raises ApiHttpClientError on success and unknown statu
290
291
const KEY = '__API_KEY__' ;
291
292
const client = new ScrapflyClient ( { key : KEY } ) ;
292
293
293
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
294
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
294
295
const result = resultFactory ( {
295
296
url : config . url ,
296
297
status : 'ERR::NEW' ,
@@ -317,7 +318,7 @@ Deno.test('scrape errors: raises UpstreamHttpServerError on failure, ERR::SCRAPE
317
318
const KEY = '__API_KEY__' ;
318
319
const client = new ScrapflyClient ( { key : KEY } ) ;
319
320
320
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
321
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
321
322
const result = resultFactory ( {
322
323
url : config . url ,
323
324
success : false ,
@@ -346,7 +347,7 @@ Deno.test('scrape errors: raises UpstreamHttpClientError on failure, ERR::SCRAPE
346
347
const KEY = '__API_KEY__' ;
347
348
const client = new ScrapflyClient ( { key : KEY } ) ;
348
349
349
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
350
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
350
351
const result = resultFactory ( {
351
352
url : config . url ,
352
353
success : false ,
@@ -385,7 +386,7 @@ Deno.test('scrape errors: raises resource exceptions on failure', async () => {
385
386
} ;
386
387
387
388
for ( const [ resource , err ] of Object . entries ( resourceErrMap ) ) {
388
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
389
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
389
390
const result = resultFactory ( {
390
391
url : config . url ,
391
392
success : false ,
@@ -414,7 +415,7 @@ Deno.test('scrape errors: raises ScrapflyError on unhandled failure', async () =
414
415
const KEY = '__API_KEY__' ;
415
416
const client = new ScrapflyClient ( { key : KEY } ) ;
416
417
417
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
418
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
418
419
const result = resultFactory ( {
419
420
url : config . url ,
420
421
success : false ,
@@ -443,7 +444,7 @@ Deno.test('scrape errors: account retrieval status unhandled code (e.g. 404)', a
443
444
const KEY = '__API_KEY__' ;
444
445
const client = new ScrapflyClient ( { key : KEY } ) ;
445
446
446
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
447
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
447
448
return responseFactory (
448
449
{ } ,
449
450
{
@@ -466,7 +467,7 @@ Deno.test('scrape errors: account retrieval bad api key (status 401)', async ()
466
467
const KEY = '__API_KEY__' ;
467
468
const client = new ScrapflyClient ( { key : KEY } ) ;
468
469
469
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
470
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
470
471
return responseFactory (
471
472
{ } ,
472
473
{
@@ -496,7 +497,7 @@ Deno.test('concurrent scrape: success with explicit concurrency', async () => {
496
497
const results = [ ] ;
497
498
const errors = [ ] ;
498
499
499
- const fetchStub = stub ( client , 'fetch' , async ( config : Request ) : Promise < Response > => {
500
+ const fetchStub = stub ( client , 'fetch' , async ( config : RequestOptions ) : Promise < Response > => {
500
501
await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ; // XXX: NEEDS a delay!
501
502
log . error ( config . url ) ;
502
503
if ( config . url . includes ( '200' ) ) {
0 commit comments