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.

chore: fix TypeScript errors in tests

Jindřich Bär8d53131ea518
diff --git a/package.json b/package.json
index 588be6428..c87247385 100644
--- a/package.json
+++ b/package.json
@@ -102,6 +102,7 @@
"globby": "^15.0.0",
"got": "^14.4.7",
"husky": "^9.1.7",
+ "iconv-lite": "^0.7.2",
"is-ci": "^4.1.0",
"lerna": "^9.0.0",
"lint-staged": "^17.0.0",
diff --git a/packages/http-crawler/package.json b/packages/http-crawler/package.json
index 6cb9ce155..ccf61a617 100644
--- a/packages/http-crawler/package.json
+++ b/packages/http-crawler/package.json
@@ -56,7 +56,7 @@
"@types/content-type": "^1.1.8",
"cheerio": "^1.0.0",
"content-type": "^1.0.5",
- "iconv-lite": "^0.7.0",
+ "iconv-lite": "^0.7.2",
"mime-types": "^3.0.1",
"ow": "^2.0.0",
"tslib": "^2.8.1",
diff --git a/packages/http-crawler/src/internals/http-crawler.ts b/packages/http-crawler/src/internals/http-crawler.ts
index 429c1a418..cf2d18825 100644
--- a/packages/http-crawler/src/internals/http-crawler.ts
+++ b/packages/http-crawler/src/internals/http-crawler.ts
@@ -725,11 +725,9 @@ export class HttpCrawler<
if (Buffer.isEncoding(encoding)) return { response, encoding };
// Try to re-encode a variety of unsupported encodings to utf-8
- if (iconv.default.encodingExists(encoding)) {
- const encodeStream = iconv.default.encodeStream(utf8);
- const decodeStream = iconv.default
- .decodeStream(encoding)
- .on('error', (err) => encodeStream.emit('error', err));
+ if (iconv.encodingExists(encoding)) {
+ const encodeStream = iconv.encodeStream(utf8);
+ const decodeStream = iconv.decodeStream(encoding).on('error', (err) => encodeStream.emit('error', err));
const reencodedBody = response.body
? Readable.toWeb(
Readable.from(
diff --git a/test/core/crawlers/playwright_crawler.test.ts b/test/core/crawlers/playwright_crawler.test.ts
index 0ff8a9ce5..57dd5e8dd 100644
--- a/test/core/crawlers/playwright_crawler.test.ts
+++ b/test/core/crawlers/playwright_crawler.test.ts
@@ -3,16 +3,13 @@ import type { AddressInfo } from 'node:net';
import os from 'node:os';
import type {
- Cheerio,
- CheerioAPI,
- CheerioRoot,
- Element,
PlaywrightCrawlingContext,
PlaywrightGotoOptions,
PlaywrightRequestHandler,
Request,
} from '@crawlee/playwright';
import { createPlaywrightRouter, PlaywrightCrawler, RequestList, RequestValidationError } from '@crawlee/playwright';
+import type { Cheerio, CheerioAPI, CheerioRoot, Element } from '@crawlee/utils';
import express from 'express';
import playwright from 'playwright';
import { z } from 'zod';
diff --git a/test/core/crawlers/rendering_type_predictor.test.ts b/test/core/crawlers/rendering_type_predictor.test.ts
index de4df27ec..c96c1c360 100644
--- a/test/core/crawlers/rendering_type_predictor.test.ts
+++ b/test/core/crawlers/rendering_type_predictor.test.ts
@@ -2,7 +2,7 @@ import { Request } from '@crawlee/core';
import { RenderingTypePredictor } from '@crawlee/playwright';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { MemoryStorageEmulator } from '../../shared/MemoryStorageEmulator';
+import { MemoryStorageEmulator } from '../../shared/MemoryStorageEmulator.js';
describe('RenderingTypePredictor', () => {
const localStorageEmulator = new MemoryStorageEmulator();
diff --git a/test/stagehand-crawler/stagehand-controller.test.ts b/test/stagehand-crawler/stagehand-controller.test.ts
index 3b890af99..96e3d86dc 100644
--- a/test/stagehand-crawler/stagehand-controller.test.ts
+++ b/test/stagehand-crawler/stagehand-controller.test.ts
@@ -1,7 +1,7 @@
import log from '@apify/log';
-import { StagehandController } from '../../packages/stagehand-crawler/src/internals/stagehand-controller';
-import type { StagehandPlugin } from '../../packages/stagehand-crawler/src/internals/stagehand-plugin';
+import { StagehandController } from '../../packages/stagehand-crawler/src/internals/stagehand-controller.js';
+import type { StagehandPlugin } from '../../packages/stagehand-crawler/src/internals/stagehand-plugin.js';
describe('StagehandController', () => {
let mockPlugin: StagehandPlugin;
diff --git a/test/stagehand-crawler/stagehand-crawler.test.ts b/test/stagehand-crawler/stagehand-crawler.test.ts
index ee3257df2..319bfede4 100644
--- a/test/stagehand-crawler/stagehand-crawler.test.ts
+++ b/test/stagehand-crawler/stagehand-crawler.test.ts
@@ -1,7 +1,7 @@
import { z } from 'zod';
-import { createStagehandRouter, StagehandCrawler } from '../../packages/stagehand-crawler/src';
-import { enhancePageWithStagehand } from '../../packages/stagehand-crawler/src/internals/utils/stagehand-utils';
+import { createStagehandRouter, StagehandCrawler } from '../../packages/stagehand-crawler/src/index.js';
+import { enhancePageWithStagehand } from '../../packages/stagehand-crawler/src/internals/utils/stagehand-utils.js';
// Mock Stagehand to avoid actual browser launches and API calls
vi.mock('@browserbasehq/stagehand', () => {
diff --git a/test/stagehand-crawler/stagehand-plugin.test.ts b/test/stagehand-crawler/stagehand-plugin.test.ts
index ca8556729..a117519b0 100644
--- a/test/stagehand-crawler/stagehand-plugin.test.ts
+++ b/test/stagehand-crawler/stagehand-plugin.test.ts
@@ -1,6 +1,6 @@
import playwright from 'playwright';
-import { StagehandPlugin } from '../../packages/stagehand-crawler/src/internals/stagehand-plugin';
+import { StagehandPlugin } from '../../packages/stagehand-crawler/src/internals/stagehand-plugin.js';
// Mock Stagehand
vi.mock('@browserbasehq/stagehand', () => {