Skip to content

Commit 0a94f70

Browse files
committed
fix: update async iterator to support old node versions
1 parent bbe26e2 commit 0a94f70

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/basic-crawler/src/internals/basic-crawler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
16991699
protected async *_crawlingContextAddRequestsGenerator(
17001700
requests: RequestsLike,
17011701
crawlingContextRequest: Request<Dictionary>,
1702-
): AsyncGenerator<Source, void, Source> {
1702+
): AsyncGenerator<Source, void, undefined> {
17031703
const newRequestDepth = crawlingContextRequest.crawlDepth + 1;
17041704

17051705
for await (const request of requests) {

test/core/crawlers/basic_crawler.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Server } from 'node:http';
33
import http from 'node:http';
44
import type { AddressInfo } from 'node:net';
55

6-
import type { CrawlingContext, ErrorHandler, RequestHandler, RequestOptions } from '@crawlee/basic';
6+
import type { CrawlingContext, ErrorHandler, RequestHandler, RequestOptions, Source } from '@crawlee/basic';
77
import {
88
BasicCrawler,
99
Configuration,
@@ -300,7 +300,10 @@ describe('BasicCrawler', () => {
300300
const request = new Request({ url: 'https://example.com/', crawlDepth: 3 });
301301
const addRequestsGenerator = _crawlingContextAddRequestsGenerator(requests, request);
302302

303-
const generatedRequests = await Array.fromAsync(addRequestsGenerator);
303+
const generatedRequests: Source[] = [];
304+
for await (const generatedRequest of addRequestsGenerator) {
305+
generatedRequests.push(generatedRequest);
306+
}
304307

305308
expect(generatedRequests).toHaveLength(2);
306309
expect(generatedRequests[0].url).toBe('https://example.com/1/');

0 commit comments

Comments
 (0)