11import axios from 'axios' ;
2+ import { AxiosRequestConfig } from 'axios' ;
23import { ScrapflyClient } from '../src/client.js' ;
34import * as errors from '../src/errors.js' ;
45import { ScrapeConfig } from '../src/scrapeconfig.js' ;
6+ import { describe , it , expect , jest , beforeEach } from '@jest/globals' ;
57
68jest . mock ( 'axios' ) ;
79
@@ -37,7 +39,7 @@ describe('concurrent scrape', () => {
3739 // mock axios to return /account data and 2 types of results:
3840 // - success for /success endpoints
3941 // - ASP failure for /failure endpoints
40- mockedAxios . request . mockImplementation ( async ( config ) => {
42+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
4143 if ( config . url . includes ( '/account' ) ) {
4244 return {
4345 status : 200 ,
@@ -123,7 +125,7 @@ describe('scrape', () => {
123125
124126 it ( 'GET success' , async ( ) => {
125127 const url = 'https://httpbin.dev/json' ;
126- mockedAxios . request . mockImplementation ( async ( config ) => {
128+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
127129 // Ensure the URL matches the pattern
128130 expect ( config . url ) . toMatch ( client . HOST + '/scrape' ) ;
129131 expect ( config . method ) . toEqual ( 'GET' ) ;
@@ -147,7 +149,7 @@ describe('scrape', () => {
147149
148150 it ( 'GET complex urls' , async ( ) => {
149151 const url = 'https://httpbin.dev/anything/?website=https://httpbin.dev/anything' ;
150- mockedAxios . request . mockImplementation ( async ( config ) => {
152+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
151153 // Ensure the URL matches the pattern
152154 expect ( config . url ) . toMatch ( client . HOST + '/scrape' ) ;
153155 expect ( config . method ) . toEqual ( 'GET' ) ;
@@ -169,11 +171,9 @@ describe('scrape', () => {
169171 expect ( mockedAxios . request ) . toHaveBeenCalledTimes ( 1 ) ;
170172 } ) ;
171173
172-
173-
174174 it ( 'POST success' , async ( ) => {
175175 const url = 'https://httpbin.dev/json' ;
176- mockedAxios . request . mockImplementation ( async ( config ) => {
176+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
177177 // Ensure the URL matches the pattern
178178 expect ( config . url ) . toMatch ( client . HOST + '/scrape' ) ;
179179 expect ( config . method ) . toEqual ( 'POST' ) ;
@@ -235,7 +235,7 @@ describe('client errors', () => {
235235
236236 it ( 'raises ApiHttpServerError on 500 and success' , async ( ) => {
237237 const url = 'https://httpbin.dev/json' ;
238- mockedAxios . request . mockImplementation ( async ( config ) => {
238+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
239239 return resultFactory ( {
240240 url : config . url ,
241241 status_code : 500 ,
@@ -249,7 +249,7 @@ describe('client errors', () => {
249249
250250 it ( 'raises BadApiKeyError on 401' , async ( ) => {
251251 const url = 'https://httpbin.dev/json' ;
252- mockedAxios . request . mockImplementation ( async ( config ) => {
252+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
253253 return resultFactory ( {
254254 url : config . url ,
255255 status_code : 401 ,
@@ -262,7 +262,7 @@ describe('client errors', () => {
262262 } ) ;
263263 it ( 'raises TooManyRequests on 429 and success' , async ( ) => {
264264 const url = 'https://httpbin.dev/json' ;
265- mockedAxios . request . mockImplementation ( async ( config ) => {
265+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
266266 return resultFactory ( {
267267 url : config . url ,
268268 status_code : 429 ,
@@ -273,7 +273,7 @@ describe('client errors', () => {
273273 await expect ( client . scrape ( new ScrapeConfig ( { url } ) ) ) . rejects . toThrow ( errors . TooManyRequests ) ;
274274 } ) ;
275275 it ( 'raises ScrapflyScrapeError on ::SCRAPE:: resource and success' , async ( ) => {
276- mockedAxios . request . mockImplementation ( async ( config ) => {
276+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
277277 return resultFactory ( {
278278 url : config . url ,
279279 status : 'ERR::SCRAPE::BAD_PROTOCOL' ,
@@ -286,7 +286,7 @@ describe('client errors', () => {
286286 } ) ;
287287
288288 it ( 'raises ScrapflyWebhookError on ::WEBHOOK:: resource and success' , async ( ) => {
289- mockedAxios . request . mockImplementation ( async ( config ) => {
289+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
290290 return resultFactory ( {
291291 url : config . url ,
292292 status : 'ERR::WEBHOOK::DISABLED ' ,
@@ -298,7 +298,7 @@ describe('client errors', () => {
298298 ) ;
299299 } ) ;
300300 it ( 'raises ScrapflyProxyError on ERR::PROXY::POOL_NOT_FOUND resource and success' , async ( ) => {
301- mockedAxios . request . mockImplementation ( async ( config ) => {
301+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
302302 return resultFactory ( {
303303 url : config . url ,
304304 status : 'ERR::PROXY::POOL_NOT_FOUND ' ,
@@ -311,7 +311,7 @@ describe('client errors', () => {
311311 } ) ;
312312
313313 it ( 'raises ScrapflyScheduleError on ERR::SCHEDULE::DISABLED resource and success' , async ( ) => {
314- mockedAxios . request . mockImplementation ( async ( config ) => {
314+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
315315 return resultFactory ( {
316316 url : config . url ,
317317 status : 'ERR::SCHEDULE::DISABLED' ,
@@ -324,7 +324,7 @@ describe('client errors', () => {
324324 } ) ;
325325
326326 it ( 'raises ScrapflyAspError on ERR::ASP::SHIELD_ERROR resource and success' , async ( ) => {
327- mockedAxios . request . mockImplementation ( async ( config ) => {
327+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
328328 return resultFactory ( {
329329 url : config . url ,
330330 status : 'ERR::ASP::SHIELD_ERROR' ,
@@ -337,7 +337,7 @@ describe('client errors', () => {
337337 } ) ;
338338
339339 it ( 'raises ScrapflySessionError on ERR::SESSION::CONCURRENT_ACCESS resource and success' , async ( ) => {
340- mockedAxios . request . mockImplementation ( async ( config ) => {
340+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
341341 return resultFactory ( {
342342 url : config . url ,
343343 status : 'ERR::SESSION::CONCURRENT_ACCESS' ,
@@ -350,7 +350,7 @@ describe('client errors', () => {
350350 } ) ;
351351
352352 it ( 'raises ApiHttpClientError on success and unknown status' , async ( ) => {
353- mockedAxios . request . mockImplementation ( async ( config ) => {
353+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
354354 return resultFactory ( {
355355 url : config . url ,
356356 status : 'ERR::NEW' ,
@@ -362,7 +362,7 @@ describe('client errors', () => {
362362 ) ;
363363 } ) ;
364364 it ( 'raises UpstreamHttpServerError on failure, ERR::SCRAPE::BAD_UPSTREAM_RESPONSE and >=500' , async ( ) => {
365- mockedAxios . request . mockImplementation ( async ( config ) => {
365+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
366366 return resultFactory ( {
367367 url : config . url ,
368368 success : false ,
@@ -375,7 +375,7 @@ describe('client errors', () => {
375375 ) ;
376376 } ) ;
377377 it ( 'raises UpstreamHttpClientError on failure, ERR::SCRAPE::BAD_UPSTREAM_RESPONSE and 4xx status' , async ( ) => {
378- mockedAxios . request . mockImplementation ( async ( config ) => {
378+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
379379 return resultFactory ( {
380380 url : config . url ,
381381 success : false ,
@@ -398,7 +398,7 @@ describe('client errors', () => {
398398 SESSION : errors . ScrapflySessionError ,
399399 } ;
400400 for ( const [ resource , err ] of Object . entries ( resourceErrMap ) ) {
401- mockedAxios . request . mockImplementation ( async ( config ) => {
401+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
402402 return resultFactory ( {
403403 url : config . url ,
404404 success : false ,
@@ -410,7 +410,7 @@ describe('client errors', () => {
410410 } ) ;
411411
412412 it ( 'raises ScrapflyError on unhandled failure' , async ( ) => {
413- mockedAxios . request . mockImplementation ( async ( config ) => {
413+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
414414 return resultFactory ( {
415415 url : config . url ,
416416 success : false ,
@@ -423,7 +423,7 @@ describe('client errors', () => {
423423 ) ;
424424 } ) ;
425425 it ( 'raises on unhandled failure' , async ( ) => {
426- mockedAxios . request . mockImplementation ( async ( config ) => {
426+ mockedAxios . request . mockImplementation ( async ( config : AxiosRequestConfig ) : Promise < any > => {
427427 return resultFactory ( {
428428 url : config . url ,
429429 success : false ,
0 commit comments