@@ -2,7 +2,7 @@ import type { Server } from 'node:http';
22
33import { BROWSER_POOL_EVENTS , OperatingSystemsName , PuppeteerPlugin } from '@crawlee/browser-pool' ;
44import { BLOCKED_STATUS_CODES } from '@crawlee/core' ;
5- import type { PuppeteerCrawlingContext , PuppeteerGoToOptions } from '@crawlee/puppeteer' ;
5+ import type { PuppeteerGoToOptions } from '@crawlee/puppeteer' ;
66import { EnqueueStrategy , ProxyConfiguration , Request , RequestList , RequestState , Session } from '@crawlee/puppeteer' ;
77import { sleep } from '@crawlee/utils' ;
88import type { HTTPResponse } from 'puppeteer' ;
@@ -13,6 +13,7 @@ import { MemoryStorageEmulator } from 'test/shared/MemoryStorageEmulator.js';
1313import { ENV_VARS } from '@apify/consts' ;
1414import log from '@apify/log' ;
1515
16+ import type { TestCrawlingContext } from './basic_browser_crawler.js' ;
1617import { BrowserCrawlerTest } from './basic_browser_crawler.js' ;
1718
1819describe ( 'BrowserCrawler' , ( ) => {
@@ -64,7 +65,7 @@ describe('BrowserCrawler', () => {
6465 const processed : Request [ ] = [ ] ;
6566 const failed : Request [ ] = [ ] ;
6667 const requestList = await RequestList . open ( null , sources ) ;
67- const requestHandler = async ( { page, request, response } : PuppeteerCrawlingContext ) => {
68+ const requestHandler = async ( { page, request, response } : TestCrawlingContext ) => {
6869 await page . waitForSelector ( 'title' ) ;
6970
7071 expect ( response ! . status ( ) ) . toBe ( 200 ) ;
@@ -124,7 +125,7 @@ describe('BrowserCrawler', () => {
124125 let sessionGoto ! : Session ;
125126 const browserCrawler = new ( class extends BrowserCrawlerTest {
126127 protected override async _navigationHandler (
127- ctx : PuppeteerCrawlingContext ,
128+ ctx : TestCrawlingContext ,
128129 ) : Promise < HTTPResponse | null | undefined > {
129130 vitest . spyOn ( ctx . session ! , 'markBad' ) ;
130131 sessionGoto = ctx . session ! ;
@@ -184,6 +185,7 @@ describe('BrowserCrawler', () => {
184185 } ,
185186 requestList,
186187 useSessionPool : true ,
188+ requestHandler : async ( ) => { } ,
187189 maxRequestRetries : 0 ,
188190 postNavigationHooks : [ hook ] ,
189191 } ) ;
@@ -270,7 +272,7 @@ describe('BrowserCrawler', () => {
270272 let optionsGoto : PuppeteerGoToOptions ;
271273 const browserCrawler = new ( class extends BrowserCrawlerTest {
272274 protected override async _navigationHandler (
273- ctx : PuppeteerCrawlingContext ,
275+ ctx : TestCrawlingContext ,
274276 gotoOptions : PuppeteerGoToOptions ,
275277 ) : Promise < HTTPResponse | null | undefined > {
276278 optionsGoto = gotoOptions ;
@@ -617,7 +619,7 @@ describe('BrowserCrawler', () => {
617619 let called = false ;
618620 const browserCrawler = new ( class extends BrowserCrawlerTest {
619621 protected override async _navigationHandler (
620- ctx : PuppeteerCrawlingContext ,
622+ ctx : TestCrawlingContext ,
621623 ) : Promise < HTTPResponse | null | undefined > {
622624 browserCrawler . browserPool . on ( BROWSER_POOL_EVENTS . BROWSER_RETIRED , ( ) => {
623625 resolve ( ) ;
@@ -841,7 +843,7 @@ describe('BrowserCrawler', () => {
841843
842844 const browserCrawler = new ( class extends BrowserCrawlerTest {
843845 protected override async _navigationHandler (
844- ctx : PuppeteerCrawlingContext ,
846+ ctx : TestCrawlingContext ,
845847 ) : Promise < HTTPResponse | null | undefined > {
846848 const { session } = ctx ;
847849 const proxyInfo = await this . proxyConfiguration ! . newProxyInfo ( session ?. id ) ;
@@ -880,7 +882,7 @@ describe('BrowserCrawler', () => {
880882 let numberOfRotations = - requestList ! . length ( ) ;
881883 const browserCrawler = new ( class extends BrowserCrawlerTest {
882884 protected override async _navigationHandler (
883- ctx : PuppeteerCrawlingContext ,
885+ ctx : TestCrawlingContext ,
884886 ) : Promise < HTTPResponse | null | undefined > {
885887 const { session } = ctx ;
886888 const proxyInfo = await this . proxyConfiguration ! . newProxyInfo ( session ?. id ) ;
@@ -918,7 +920,7 @@ describe('BrowserCrawler', () => {
918920
919921 const crawler = new ( class extends BrowserCrawlerTest {
920922 protected override async _navigationHandler (
921- ctx : PuppeteerCrawlingContext ,
923+ ctx : TestCrawlingContext ,
922924 ) : Promise < HTTPResponse | null | undefined > {
923925 const { session } = ctx ;
924926 const proxyInfo = await this . proxyConfiguration ! . newProxyInfo ( session ?. id ) ;
@@ -967,16 +969,16 @@ describe('BrowserCrawler', () => {
967969 } ) ;
968970
969971 test ( 'uses correct crawling context' , async ( ) => {
970- let prepareCrawlingContext : PuppeteerCrawlingContext ;
972+ let prepareCrawlingContext : TestCrawlingContext ;
971973
972- const gotoFunction = async ( crawlingContext : PuppeteerCrawlingContext ) => {
974+ const gotoFunction = async ( crawlingContext : TestCrawlingContext ) => {
973975 prepareCrawlingContext = crawlingContext ;
974976 expect ( crawlingContext . request ) . toBeInstanceOf ( Request ) ;
975977 expect ( crawlingContext . session ) . toBeInstanceOf ( Session ) ;
976978 expect ( typeof crawlingContext . page ) . toBe ( 'object' ) ;
977979 } ;
978980
979- const requestHandler = async ( crawlingContext : PuppeteerCrawlingContext ) => {
981+ const requestHandler = async ( crawlingContext : TestCrawlingContext ) => {
980982 expect ( crawlingContext === prepareCrawlingContext ) . toEqual ( true ) ;
981983 expect ( crawlingContext . request ) . toBeInstanceOf ( Request ) ;
982984 expect ( crawlingContext . session ) . toBeInstanceOf ( Session ) ;
@@ -986,7 +988,7 @@ describe('BrowserCrawler', () => {
986988 throw new Error ( 'some error' ) ;
987989 } ;
988990
989- const failedRequestHandler = async ( crawlingContext : Partial < PuppeteerCrawlingContext > , error : Error ) => {
991+ const failedRequestHandler = async ( crawlingContext : Partial < TestCrawlingContext > , error : Error ) => {
990992 expect ( crawlingContext ) . toBe ( prepareCrawlingContext ) ;
991993 expect ( crawlingContext . request ) . toBeInstanceOf ( Request ) ;
992994 expect ( crawlingContext . session ) . toBeInstanceOf ( Session ) ;
0 commit comments