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
Added unit test for Apify.Request
Jan Curnef3939b4a1e7
diff --git a/src/request.js b/src/request.jsindex 9a2bf4f52..f95be091a 100644--- a/src/request.js+++ b/src/request.js@@ -1,3 +1,4 @@+import _ from 'underscore';import util from 'util';import { checkParamOrThrow } from 'apify-client/build/utils';import { normalizeUrl } from 'apify-shared/utilities';@@ -139,7 +140,12 @@ class Request {this.errorMessages = errorMessages;this.headers = headers;this.userData = userData;- this.handledAt = handledAt && new Date(handledAt);++ // TODO: What is this text parsing good for? There's no unit test for it...+ // eslint-disable-next-line no-nested-ternary+ this.handledAt = _.isDate(handledAt)+ ? handledAt+ : (handledAt ? new Date(handledAt) : null);}/**diff --git a/test/request.js b/test/request.jsindex 0a431a165..276b4a8ea 100644--- a/test/request.js+++ b/test/request.js@@ -18,6 +18,29 @@ describe('Apify.Request', () => {expect(normalizedUrl).to.not.eql(url);});+ it('works', () => {+ const data = {+ id: '123',+ url: 'http://www.example.com',+ uniqueKey: 'uniq',+ method: 'POST',+ payload: 'Some payload',+ noRetry: true,+ retryCount: 1,+ errorMessages: [+ 'Something bad',+ ],+ headers: {+ Test: 'Bla',+ },+ userData: {+ yo: 123,+ },+ handledAt: new Date(),+ };+ expect(new Apify.Request(data)).to.include(data);+ });+it('should allow to push error messages', () => {const request = new Apify.Request({ url: 'http://example.com' });