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.

Merge branch 'develop' into feature/request_queue_fix

Marek Trunkát6f70a3aa09b5
diff --cc test/request_queue.js
index 40b737cd4,2b3850c9d..5bc875de1
--- a/test/request_queue.js
+++ b/test/request_queue.js
@@@ -425,47 -433,16 +433,55 @@@ describe('RequestQueue', () =>
expect(await queue.fetchNextRequest()).to.be.eql(requestA);
mock.verify();
+ mock.restore();
+ });
+
+ it('should not add handled request to queue head dict', async () => {
+ expectNotUsingLocalStorage();
+
+ const { Request } = Apify;
+
+ const queue = new RequestQueue('some-id', 'some-name');
+ const mock = sinon.mock(apifyClient.requestQueues);
+
+ const requestA = new Request({ url: 'http://example.com/a' });
+
+ mock.expects('addRequest')
+ .once()
+ .withArgs({
+ queueId: 'some-id',
+ request: requestA,
+ forefront: true,
+ })
+ .returns(Promise.resolve({
+ requestId: 'a',
+ wasAlreadyHandled: true,
+ wasAlreadyPresent: true,
+ }));
+ mock.expects('getRequest')
+ .never();
+ mock.expects('getHead')
+ .once()
+ .withArgs({
+ queueId: 'some-id',
+ limit: QUERY_HEAD_MIN_LENGTH,
+ })
+ .returns(Promise.resolve({ items: [] }));
+
+ await queue.addRequest(requestA, { forefront: true });
+ expect(await queue.fetchNextRequest()).to.be.eql(null);
+
+ mock.verify();
mock.restore();
});
+
+ it('should accept Request constructor object in addRequest()', async () => {
+ expectNotUsingLocalStorage();
+ const queue = new RequestQueue('some-id');
+ expect(() => {
+ queue.addRequest({ url: 'http://example.com/a' });
+ }).to.not.throw();
+ });
});
describe('Apify.openRequestQueue', async () => {