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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Add test
Ondra Urban734bcca62218
diff --git a/test/cheerio_crawler.js b/test/cheerio_crawler.jsindex 6630b3195..03d18da49 100644--- a/test/cheerio_crawler.js+++ b/test/cheerio_crawler.js@@ -407,4 +407,70 @@ describe('CheerioCrawler', () => {});});});++ // It would make sense to also test that the listener does not prevent other+ // uncaught exceptions from exiting the process, but since the exceptions+ // thrown from within the listener cannot be caught anymore, there's no way+ // to do this, because the re-thrown error will always crash the test process.+ describe('tunnel-agent error handler', () => {+ const throwNextTick = (err) => {+ process.nextTick(() => {+ throw err;+ });+ };++ let mochaListener;++ before(() => {+ log.setLevel(log.LEVELS.OFF);+ mochaListener = process.listeners('uncaughtException').shift();+ process.removeListener('uncaughtException', mochaListener);+ });+ after(() => {+ log.setLevel(log.LEVELS.ERROR);+ process.on('uncaughtException', mochaListener);+ });++ it('should suppress tunnel-agent errors', async () => {+ let handlePageCalled = false;+ let handleFailedRequestCallCount = 0;++ const requestList = new Apify.RequestList({+ sources: [+ { url: 'http://example.com/?q=0' },+ { url: 'http://example.com/?q=1' },+ { url: 'http://example.com/?q=2' },+ { url: 'http://example.com/?q=3' },+ ],+ });++ const crawler = new Apify.CheerioCrawler({+ requestList,+ requestFunction: async () => {+ const err = new Error();+ err.code = 'ERR_ASSERTION';+ err.name = 'AssertionError [ERR_ASSERTION]';+ err.operator = '==';+ err.expected = 0;+ err.stack = ('xxx/tunnel-agent/index.js/yyyy');+ throwNextTick(err);+ // will never resolve+ await new Promise((r, rj) => {}); // eslint-disable-line no-unused-vars+ },+ requestTimeoutSecs: 1 / 1000,+ handlePageFunction: () => {+ handlePageCalled = true;+ },+ handleFailedRequestFunction: () => {+ handleFailedRequestCallCount++;+ },+ });++ await requestList.initialize();+ await crawler.run();++ expect(handlePageCalled).to.be.eql(false);+ expect(handleFailedRequestCallCount).to.be.eql(4);+ });+ });});