Skip to content

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.

fixed tests

Petr Patek97b0beeabdb2
diff --git a/package.json b/package.json
index c575bc248..0a633ad56 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,7 @@
"lint:fix": "./node_modules/.bin/eslint ./src ./test --ext .js,.jsx --fix"
},
"dependencies": {
- "@apify/http-request": "^1.1.0",
+ "@apify/http-request": "^1.1.1",
"@apify/ps-tree": "^1.1.3",
"apify-client": "^0.5.25",
"apify-shared": "^0.1.56",
diff --git a/test/crawlers/cheerio_crawler.js b/test/crawlers/cheerio_crawler.js
index a4a241089..bc03acd68 100644
--- a/test/crawlers/cheerio_crawler.js
+++ b/test/crawlers/cheerio_crawler.js
@@ -7,12 +7,8 @@ import { delayPromise } from 'apify-shared/utilities';
import { ENV_VARS } from 'apify-shared/consts';
import express from 'express';
import bodyParser from 'body-parser';
-import sinon from 'sinon';
-import * as utilsRequest from '../../build/utils_request';
import Apify from '../../build';
-const Stream = require('stream');
-
// Add common props to mocked request responses.
const responseMock = {
url: 'loadedUrl',
@@ -103,10 +99,10 @@ describe('CheerioCrawler', () => {
res.send({ some: 'json' });
});
- app.get('/jsonError', (req, res) => {
+ app.post('/jsonError', (req, res) => {
res
.status(500)
- .json({ message: 'json' });
+ .json({ message: 'CUSTOM_ERROR' });
});
@@ -430,24 +426,6 @@ describe('CheerioCrawler', () => {
});
it('when statusCode >= 500 and application/json is received', async () => {
- const save = sinon.stub(utilsRequest, 'requestAsBrowser');
- const errorMessage = 'TEST_ERROR';
- save.callsFake(() => new Promise((resolve) => {
- const readableStream = new Stream.Readable();
- readableStream._read = function () {
- this.push(Buffer.from(JSON.stringify({ message: errorMessage })));
- this.push(null);
- };
-
- const finalStream = new Stream.PassThrough();
- finalStream.statusCode = 500;
- finalStream.headers = {
- 'content-type': 'application/json',
- };
- resolve(readableStream.pipe(finalStream));
- }));
-
-
crawler = new Apify.CheerioCrawler({
requestList: await getRequestListForMock({}, 'jsonError'),
maxRequestRetries: 1,
@@ -459,11 +437,10 @@ describe('CheerioCrawler', () => {
},
});
await crawler.run();
- save.restore();
expect(handlePageInvocationCount).to.be.eql(0);
expect(errorMessages).to.have.lengthOf(8);
- errorMessages.forEach(msg => expect(msg).to.include(errorMessage));
+ errorMessages.forEach(msg => expect(msg).to.include('CUSTOM_ERROR'));
});
it('when 406 is received', async () => {