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.

feat: make `cheerio` and `proxy-chain` imports dynamic (#3836)

Jindřich Bärfcca6fee894b
diff --git a/docs/public-api/crawlee-jsdom.api.md b/docs/public-api/crawlee-jsdom.api.md
index 2ecbc1013..d61106110 100644
--- a/docs/public-api/crawlee-jsdom.api.md
+++ b/docs/public-api/crawlee-jsdom.api.md
@@ -9,7 +9,7 @@ import { ArrayPredicate } from 'ow';
import { BasePredicate } from 'ow';
import type { BasicCrawlingContext } from '@crawlee/http';
import { BooleanPredicate } from 'ow';
-import * as cheerio from 'cheerio';
+import { CheerioAPI } from 'cheerio';
import { CheerioRoot } from '@crawlee/utils';
import { ContextPipeline } from '@crawlee/http';
import { CrawlingContext } from '@crawlee/http';
@@ -51,7 +51,7 @@ export class JSDOMCrawler<ContextExtension = Dictionary<never>, ExtendedContext
} & {
enqueueLinks: (enqueueOptions?: EnqueueLinksOptions) => Promise<unknown>;
waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
- parseWithCheerio(selector?: string, _timeoutMs?: number): Promise<cheerio.CheerioAPI>;
+ parseWithCheerio(selector?: string, _timeoutMs?: number): Promise<CheerioAPI>;
}>;
getVirtualConsole(): VirtualConsole;
// (undocumented)
diff --git a/docs/public-api/crawlee-utils.api.md b/docs/public-api/crawlee-utils.api.md
index 31849b2f1..8dab11f51 100644
--- a/docs/public-api/crawlee-utils.api.md
+++ b/docs/public-api/crawlee-utils.api.md
@@ -140,7 +140,7 @@ export function getMemoryInfo(options?: {
export function getObjectType(value: unknown): string;
// @public
-export function htmlToText(htmlOrCheerioElement: string | CheerioRoot): string;
+export function htmlToText(htmlOrCheerioElement: string | CheerioRoot): Promise<string>;
// @internal
export function inspectValue(value: unknown): string;
@@ -204,13 +204,13 @@ export interface OpenGraphProperty {
}
// @public
-function parseHandlesFromHtml(html: string, data?: Record<string, unknown> | null): SocialHandles;
+function parseHandlesFromHtml(html: string, data?: Record<string, unknown> | null): Promise<SocialHandles>;
// @public
-export function parseOpenGraph(raw: string, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
+export function parseOpenGraph(raw: string, additionalProperties?: OpenGraphProperty[]): Promise<Dictionary<OpenGraphResult>>;
// @public (undocumented)
-export function parseOpenGraph($: CheerioAPI, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
+export function parseOpenGraph($: CheerioAPI, additionalProperties?: OpenGraphProperty[]): Promise<Dictionary<OpenGraphResult>>;
// @public (undocumented)
export function parseSitemap<T extends ParseSitemapOptions>(initialSources: SitemapSource[], proxyUrl?: string, options?: T): AsyncIterable<T['emitNestedSitemaps'] extends true ? SitemapUrl | NestedSitemap : SitemapUrl>;
diff --git a/docs/upgrading/upgrading_v4.md b/docs/upgrading/upgrading_v4.md
index e0a671f69..52f98f48f 100644
--- a/docs/upgrading/upgrading_v4.md
+++ b/docs/upgrading/upgrading_v4.md
@@ -342,6 +342,10 @@ The `CrawlingContext.response` property is now of type [`Response`](https://deve
The crawling context in the `FileDownload` crawler no longer includes the `body` and `stream` properties. These can be accessed directly via the `response` property instead, e.g. `context.response.bytes()` or `context.response.body`.
+## HTML-parsing helper functions are now asynchronous
+
+The HTML-parsing helper functions `htmlToText`, `parseHandlesFromHtml` and `parseOpenGraph` are now asynchronous and return promises.
+
## `KeyValueStore.getPublicUrl` is now async
The `KeyValueStore.getPublicUrl` method is now asynchronous and reads the public URL directly from the storage backend.
diff --git a/packages/browser-pool/src/anonymize-proxy.ts b/packages/browser-pool/src/anonymize-proxy.ts
index d8bc12caf..33b7176f5 100644
--- a/packages/browser-pool/src/anonymize-proxy.ts
+++ b/packages/browser-pool/src/anonymize-proxy.ts
@@ -1,5 +1,3 @@
-import { anonymizeProxy, closeAnonymizedProxy } from 'proxy-chain';
-
type PromiseVoid = () => Promise<void>;
export interface AnonymizeProxySugarOptions {
@@ -24,6 +22,7 @@ export const anonymizeProxySugar = async (
if (url.username || url.password || options?.ignoreProxyCertificate) {
// trim off trailing slash if it's present
const proxyUrlString = url.href.endsWith('/') ? url.href.slice(0, -1) : url.href;
+ const { anonymizeProxy, closeAnonymizedProxy } = await import('proxy-chain');
const anonymized = await anonymizeProxy({
url: proxyUrlString,
port: 0,
diff --git a/packages/http-crawler/src/internals/http-crawler.ts b/packages/http-crawler/src/internals/http-crawler.ts
index 2c16a4e76..3a961e129 100644
--- a/packages/http-crawler/src/internals/http-crawler.ts
+++ b/packages/http-crawler/src/internals/http-crawler.ts
@@ -28,7 +28,6 @@ import { type LoadedRequest, getCookiesFromResponse } from '@crawlee/core';
import { ResponseWithUrl } from '@crawlee/http-client';
import type { Awaitable, Dictionary, ISession } from '@crawlee/types';
import { type CheerioRoot, RETRY_CSS_SELECTORS } from '@crawlee/utils';
-import * as cheerio from 'cheerio';
import type { RequestLike, ResponseLike } from 'content-type';
import contentTypeParser from 'content-type';
import iconv from 'iconv-lite';
@@ -515,6 +514,7 @@ export class HttpCrawler<
const contentType = parsed.contentType!;
const waitForSelector = async (selector: string, _timeoutMs?: number) => {
+ const cheerio = await import('cheerio');
const $ = cheerio.load(parsed.body!.toString());
if ($(selector).get().length === 0) {
@@ -522,6 +522,7 @@ export class HttpCrawler<
}
};
const parseWithCheerio = async (selector?: string, timeoutMs?: number) => {
+ const cheerio = await import('cheerio');
const $ = cheerio.load(parsed.body!.toString());
if (selector) {
diff --git a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
index 7d35f59c6..2735dffe1 100644
--- a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
+++ b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
@@ -24,7 +24,6 @@ import {
} from '@crawlee/http';
import type { Dictionary } from '@crawlee/types';
import { type CheerioRoot, type RobotsTxtFile, sleep } from '@crawlee/utils';
-import * as cheerio from 'cheerio';
import type { DOMWindow } from 'jsdom';
import { JSDOM, ResourceLoader, VirtualConsole } from 'jsdom';
import ow from 'ow';
@@ -367,6 +366,7 @@ export class JSDOMCrawler<
});
},
async waitForSelector(selector: string, timeoutMs = 5_000) {
+ const cheerio = await import('cheerio');
const $ = cheerio.load(crawlingContext.body);
if ($(selector).get().length === 0) {
@@ -380,6 +380,7 @@ export class JSDOMCrawler<
}
},
async parseWithCheerio(selector?: string, _timeoutMs = 5_000) {
+ const cheerio = await import('cheerio');
const $ = cheerio.load(crawlingContext.body);
if (selector && $(selector).get().length === 0) {
diff --git a/packages/utils/src/internals/cheerio.ts b/packages/utils/src/internals/cheerio.ts
index ae67ddb8f..149533abb 100644
--- a/packages/utils/src/internals/cheerio.ts
+++ b/packages/utils/src/internals/cheerio.ts
@@ -1,6 +1,5 @@
import type { Dictionary } from '@crawlee/types';
import type { CheerioAPI } from 'cheerio';
-import * as cheerio from 'cheerio';
import { tryAbsoluteURL } from './extract-urls.js';
@@ -40,10 +39,12 @@ const BLOCK_TAGS_REGEX =
* @param htmlOrCheerioElement HTML text or parsed HTML represented using a [cheerio](https://www.npmjs.com/package/cheerio) function.
* @return Plain text
*/
-export function htmlToText(htmlOrCheerioElement: string | CheerioRoot): string {
+export async function htmlToText(htmlOrCheerioElement: string | CheerioRoot): Promise<string> {
+ const { load } = await import('cheerio');
+
if (!htmlOrCheerioElement) return '';
- const $ = typeof htmlOrCheerioElement === 'function' ? htmlOrCheerioElement : cheerio.load(htmlOrCheerioElement);
+ const $ = typeof htmlOrCheerioElement === 'function' ? htmlOrCheerioElement : load(htmlOrCheerioElement);
let text = '';
const process = (elems: Dictionary) => {
diff --git a/packages/utils/src/internals/open_graph_parser.ts b/packages/utils/src/internals/open_graph_parser.ts
index 7d80bf3d0..3290f6b79 100644
--- a/packages/utils/src/internals/open_graph_parser.ts
+++ b/packages/utils/src/internals/open_graph_parser.ts
@@ -1,6 +1,5 @@
import type { Dictionary } from '@crawlee/types';
import type { CheerioAPI } from 'cheerio';
-import { load } from 'cheerio';
export interface OpenGraphProperty {
name: string;
@@ -395,9 +394,16 @@ const parseOpenGraphProperty = (property: OpenGraphProperty, $: CheerioAPI): str
* Currently existing properties are kept up to date.
* @returns Scraped OpenGraph properties as an object.
*/
-export function parseOpenGraph(raw: string, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
-export function parseOpenGraph($: CheerioAPI, additionalProperties?: OpenGraphProperty[]): Dictionary<OpenGraphResult>;
-export function parseOpenGraph(item: CheerioAPI | string, additionalProperties?: OpenGraphProperty[]) {
+export async function parseOpenGraph(
+ raw: string,
+ additionalProperties?: OpenGraphProperty[],
+): Promise<Dictionary<OpenGraphResult>>;
+export async function parseOpenGraph(
+ $: CheerioAPI,
+ additionalProperties?: OpenGraphProperty[],
+): Promise<Dictionary<OpenGraphResult>>;
+export async function parseOpenGraph(item: CheerioAPI | string, additionalProperties?: OpenGraphProperty[]) {
+ const { load } = await import('cheerio');
const $ = typeof item === 'string' ? load(item) : item;
return [...(additionalProperties || []), ...OPEN_GRAPH_PROPERTIES].reduce((acc, curr) => {
diff --git a/packages/utils/src/internals/social.ts b/packages/utils/src/internals/social.ts
index cbeac1131..9977d6504 100644
--- a/packages/utils/src/internals/social.ts
+++ b/packages/utils/src/internals/social.ts
@@ -1,5 +1,3 @@
-import * as cheerio from 'cheerio';
-
import { htmlToText } from './cheerio.js';
// Regex inspired by https://zapier.com/blog/extract-links-email-phone-regex/
@@ -661,7 +659,12 @@ export const DISCORD_REGEX_GLOBAL = new RegExp(DISCORD_REGEX_STRING, 'ig');
* so that the caller doesn't need to parse the HTML document again, if needed.
* @return An object with the social handles.
*/
-export function parseHandlesFromHtml(html: string, data: Record<string, unknown> | null = null): SocialHandles {
+export async function parseHandlesFromHtml(
+ html: string,
+ data: Record<string, unknown> | null = null,
+): Promise<SocialHandles> {
+ const cheerio = await import('cheerio');
+
const result: SocialHandles = {
emails: [],
phones: [],
@@ -681,7 +684,7 @@ export function parseHandlesFromHtml(html: string, data: Record<string, unknown>
const $ = cheerio.load(html, { xml: { decodeEntities: true } });
if (data) data.$ = $;
- const text = htmlToText($);
+ const text = await htmlToText($);
if (data) data.text = text;
// NOTE: we need to parse each text separately, orherwise we might concatenate unrelated texts
diff --git a/test/browser-pool/anonymize-proxy-sugar.test.ts b/test/browser-pool/anonymize-proxy-sugar.test.ts
index c21bc7be1..ea93e2ba5 100644
--- a/test/browser-pool/anonymize-proxy-sugar.test.ts
+++ b/test/browser-pool/anonymize-proxy-sugar.test.ts
@@ -8,6 +8,7 @@ describe('anonymizeProxySugar', () => {
beforeEach(() => {
vi.mock('proxy-chain', () => ({
anonymizeProxy: vi.fn((opts) => Promise.resolve(`anonymized-${opts.url}`)),
+ closeAnonymizedProxy: vi.fn(() => Promise.resolve()),
}));
});
diff --git a/test/utils/cheerio.test.ts b/test/utils/cheerio.test.ts
index b3da6832d..65e2aeff5 100644
--- a/test/utils/cheerio.test.ts
+++ b/test/utils/cheerio.test.ts
@@ -4,8 +4,8 @@ import * as cheerio from 'cheerio';
import * as htmlToTextData from '../shared/data/html_to_text_test_data.js';
-const checkHtmlToText = (html: string | CheerioRoot, expectedText: string, hasBody = false) => {
- const text1 = htmlToText(html);
+const checkHtmlToText = async (html: string | CheerioRoot, expectedText: string, hasBody = false) => {
+ const text1 = await htmlToText(html);
expect(text1).toEqual(expectedText);
// Test embedding into <body> gives the same result
@@ -25,62 +25,65 @@ const checkHtmlToText = (html: string | CheerioRoot, expectedText: string, hasBo
${html}
</body>
</html>`;
- const text2 = htmlToText(html2);
+ const text2 = await htmlToText(html2);
expect(text2).toEqual(expectedText);
}
};
describe('htmlToText()', () => {
- test('handles invalid args', () => {
+ test('handles invalid args', async () => {
// @ts-expect-error invalid input type
- checkHtmlToText(null, '');
- checkHtmlToText('', '');
+ await checkHtmlToText(null, '');
+ await checkHtmlToText('', '');
// @ts-expect-error invalid input type
- checkHtmlToText(0, '');
+ await checkHtmlToText(0, '');
// @ts-expect-error invalid input type
- checkHtmlToText(undefined, '');
+ await checkHtmlToText(undefined, '');
});
- test('handles basic HTML elements correctly', () => {
- checkHtmlToText('Plain text node', 'Plain text node');
- checkHtmlToText(' Plain text node ', 'Plain text node');
- checkHtmlToText(' \nPlain text node \n ', 'Plain text node');
-
- checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2>', 'Header 1\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br>', 'Header 1\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br><br>', 'Header 1\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br><br><br>', 'Header 1\nHeader 2');
-
- checkHtmlToText('<h1>Header 1</h1><br><h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> <br> <h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> \n <br>\n<h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
- checkHtmlToText('<h1>Header 1</h1> \n <br>\n<br><h2>Header 2</h2><br><br><br>', 'Header 1\n\n\nHeader 2');
- checkHtmlToText(
+ test('handles basic HTML elements correctly', async () => {
+ await checkHtmlToText('Plain text node', 'Plain text node');
+ await checkHtmlToText(' Plain text node ', 'Plain text node');
+ await checkHtmlToText(' \nPlain text node \n ', 'Plain text node');
+
+ await checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2>', 'Header 1\nHeader 2');
+ await checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br>', 'Header 1\nHeader 2');
+ await checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br><br>', 'Header 1\nHeader 2');
+ await checkHtmlToText('<h1>Header 1</h1> <h2>Header 2</h2><br><br><br>', 'Header 1\nHeader 2');
+
+ await checkHtmlToText('<h1>Header 1</h1><br><h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
+ await checkHtmlToText('<h1>Header 1</h1> <br> <h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
+ await checkHtmlToText('<h1>Header 1</h1> \n <br>\n<h2>Header 2</h2><br><br><br>', 'Header 1\n\nHeader 2');
+ await checkHtmlToText(
+ '<h1>Header 1</h1> \n <br>\n<br><h2>Header 2</h2><br><br><br>',
+ 'Header 1\n\n\nHeader 2',
+ );
+ await checkHtmlToText(
'<h1>Header 1</h1> \n <br>\n<br><br><h2>Header 2</h2><br><br><br>',
'Header 1\n\n\n\nHeader 2',
);
- checkHtmlToText('<div><div>Div</div><p>Paragraph</p></div>', 'Div\nParagraph');
- checkHtmlToText('<div>Div1</div><!-- Some comments --><div>Div2</div>', 'Div1\nDiv2');
+ await checkHtmlToText('<div><div>Div</div><p>Paragraph</p></div>', 'Div\nParagraph');
+ await checkHtmlToText('<div>Div1</div><!-- Some comments --><div>Div2</div>', 'Div1\nDiv2');
- checkHtmlToText('<div>Div1</div><style>Skip styles</style>', 'Div1');
- checkHtmlToText('<script>Skip_scripts();</script><div>Div1</div>', 'Div1');
- checkHtmlToText('<SCRIPT>Skip_scripts();</SCRIPT><div>Div1</div>', 'Div1');
- checkHtmlToText('<svg>Skip svg</svg><div>Div1</div>', 'Div1');
- checkHtmlToText('<canvas>Skip canvas</canvas><div>Div1</div>', 'Div1');
+ await checkHtmlToText('<div>Div1</div><style>Skip styles</style>', 'Div1');
+ await checkHtmlToText('<script>Skip_scripts();</script><div>Div1</div>', 'Div1');
+ await checkHtmlToText('<SCRIPT>Skip_scripts();</SCRIPT><div>Div1</div>', 'Div1');
+ await checkHtmlToText('<svg>Skip svg</svg><div>Div1</div>', 'Div1');
+ await checkHtmlToText('<canvas>Skip canvas</canvas><div>Div1</div>', 'Div1');
- checkHtmlToText('<b>A B C D E\n\nF G</b>', 'A B C D E F G');
- checkHtmlToText('<pre>A B C D E\n\nF G</pre>', 'A B C D E\n\nF G');
+ await checkHtmlToText('<b>A B C D E\n\nF G</b>', 'A B C D E F G');
+ await checkHtmlToText('<pre>A B C D E\n\nF G</pre>', 'A B C D E\n\nF G');
- checkHtmlToText(
+ await checkHtmlToText(
'<h1>Heading 1</h1><div><div><div><div>Deep Div</div></div></div></div><h2>Heading 2</h2>',
'Heading 1\nDeep Div\nHeading 2',
);
- checkHtmlToText('<a>this_word</a>_should_<b></b>be_<span>one</span>', 'this_word_should_be_one');
- checkHtmlToText('<span attributes="should" be="ignored">some <span>text</span></span>', 'some text');
+ await checkHtmlToText('<a>this_word</a>_should_<b></b>be_<span>one</span>', 'this_word_should_be_one');
+ await checkHtmlToText('<span attributes="should" be="ignored">some <span>text</span></span>', 'some text');
- checkHtmlToText(
+ await checkHtmlToText(
`<table>
<tr>
<td>Cell A1</td><td>Cell A2</td>
@@ -94,21 +97,21 @@ describe('htmlToText()', () => {
);
});
- test('handles HTML entities correctly', () => {
- checkHtmlToText('<span>&aacute; &eacute;</span>', 'á é');
+ test('handles HTML entities correctly', async () => {
+ await checkHtmlToText('<span>&aacute; &eacute;</span>', 'á é');
});
- test('handles larger HTML documents', () => {
+ test('handles larger HTML documents', async () => {
const { html, text } = htmlToTextData;
// Careful here - don't change any whitespace in the text below or the test will break, even trailing!
- checkHtmlToText(html, text, true);
+ await checkHtmlToText(html, text, true);
});
- test('works with Cheerio object', () => {
+ test('works with Cheerio object', async () => {
const html1 = '<html><body>Some text</body></html>';
- checkHtmlToText(cheerio.load(html1), 'Some text');
+ await checkHtmlToText(cheerio.load(html1), 'Some text');
const html2 = '<h1>Text outside of body</h1>';
- checkHtmlToText(cheerio.load(html2), 'Text outside of body');
+ await checkHtmlToText(cheerio.load(html2), 'Text outside of body');
});
});
diff --git a/test/utils/open_graph_parser.test.ts b/test/utils/open_graph_parser.test.ts
index 0d490d578..b098082af 100644
--- a/test/utils/open_graph_parser.test.ts
+++ b/test/utils/open_graph_parser.test.ts
@@ -29,15 +29,15 @@ describe('parseOpenGraph', () => {
<meta property="article:section" content="Tech"/>
<meta property="article:tag" content="ai"/>`);
- it('Should scrape properties', () => {
- expect(parseOpenGraph(case1)).toEqual({
+ it('Should scrape properties', async () => {
+ expect(await parseOpenGraph(case1)).toEqual({
title: 'Under Pressure',
type: 'music.song',
});
});
- it('Should return a property as an array if there are multiple attributes under the same property name', () => {
- const parsed = parseOpenGraph(case2) as {
+ it('Should return a property as an array if there are multiple attributes under the same property name', async () => {
+ const parsed = (await parseOpenGraph(case2)) as {
videoInfo: { actor: { actorValue: string[] } };
};
@@ -46,7 +46,7 @@ describe('parseOpenGraph', () => {
expect(parsed.videoInfo.actor.actorValue).toContain('bar');
expect(parsed.videoInfo.actor.actorValue).toContain('baz');
- const parsed2 = parseOpenGraph(case3) as {
+ const parsed2 = (await parseOpenGraph(case3)) as {
locale: { localeValue: string; alternate: string[] };
};
@@ -55,14 +55,14 @@ describe('parseOpenGraph', () => {
expect(parsed2.locale.alternate).toContain('bar');
});
- it('Should parse properties regardless of how deeply they are nested', () => {
- expect(parseOpenGraph(case4)).toEqual({
+ it('Should parse properties regardless of how deeply they are nested', async () => {
+ expect(await parseOpenGraph(case4)).toEqual({
musicInfo: { song: { disc: 'hello', track: 'world' } },
});
});
- it('Should accept additional OpenGraphProperties', () => {
- const parsed = parseOpenGraph(case5, [
+ it('Should accept additional OpenGraphProperties', async () => {
+ const parsed = await parseOpenGraph(case5, [
{
name: 'og:custom',
outputName: 'custom',
@@ -79,15 +79,15 @@ describe('parseOpenGraph', () => {
expect(parsed).toEqual({ custom: { test: 'hello' } });
});
- it('Should accept strings as a substitute for CheerioAPI objects', () => {
- expect(parseOpenGraph(case6)).toEqual({
+ it('Should accept strings as a substitute for CheerioAPI objects', async () => {
+ expect(await parseOpenGraph(case6)).toEqual({
title: 'My Website',
type: 'website',
});
});
- it('Should parse article properties into articleInfo', () => {
- expect(parseOpenGraph(case7)).toEqual({
+ it('Should parse article properties into articleInfo', async () => {
+ expect(await parseOpenGraph(case7)).toEqual({
type: 'article',
articleInfo: {
publishedTime: '2024-01-01T00:00:00Z',
diff --git a/test/utils/social.test.ts b/test/utils/social.test.ts
index 24260a72d..43ce49ae0 100644
--- a/test/utils/social.test.ts
+++ b/test/utils/social.test.ts
@@ -378,24 +378,24 @@ describe('utils.social', () => {
test('handles invalid arg', () => {
// @ts-expect-error invalid input type
- expect(parseHandlesFromHtml()).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml()).resolves.toEqual(EMPTY_RESULT);
// @ts-expect-error invalid input type
- expect(parseHandlesFromHtml(undefined)).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml(undefined)).resolves.toEqual(EMPTY_RESULT);
// @ts-expect-error invalid input type
- expect(parseHandlesFromHtml(null)).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml(null)).resolves.toEqual(EMPTY_RESULT);
// @ts-expect-error invalid input type
- expect(parseHandlesFromHtml({})).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml({})).resolves.toEqual(EMPTY_RESULT);
// @ts-expect-error invalid input type
- expect(parseHandlesFromHtml(1234)).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml(1234)).resolves.toEqual(EMPTY_RESULT);
});
test('works', () => {
- expect(parseHandlesFromHtml('')).toEqual(EMPTY_RESULT);
- expect(parseHandlesFromHtml(' ')).toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml('')).resolves.toEqual(EMPTY_RESULT);
+ expect(parseHandlesFromHtml(' ')).resolves.toEqual(EMPTY_RESULT);
const html =
'use the data in this [YouTube Video](https://www.youtube.com/watch?v=BsidLZKdYWQ).\\n\\n## Sample result\\n' +
'use the data in this [YouTube Video](https://www.youtube.com/watch?v=BsidLZKd123).\\\\n\\\\n## Sample result\\\\n';
- expect(parseHandlesFromHtml(html)).toMatchObject({
+ expect(parseHandlesFromHtml(html)).resolves.toMatchObject({
youtubes: [
'https://www.youtube.com/watch?v=BsidLZKd123',
'https://www.youtube.com/watch?v=BsidLZKdYWQ',
@@ -479,7 +479,7 @@ describe('utils.social', () => {
</body>
</html>
`),
- ).toEqual({
+ ).resolves.toEqual({
discords: ['discord.gg/discord-developers', 'https://discord.com/invite/jyEM2PRvMU/'],
emails: [
@@ -547,9 +547,9 @@ describe('utils.social', () => {
});
});
- test('data is set correctly', () => {
+ test('data is set correctly', async () => {
const data = {} as any;
- parseHandlesFromHtml(
+ await parseHandlesFromHtml(
`
<html>
<head>