Skip to content

Commit

Permalink
update cheerio to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum committed Dec 2, 2024
1 parent 95eeef1 commit ba7bbd5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
57 changes: 49 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions test/helpers/playwright-fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Page, Request, Response } from "@playwright/test";
import { test } from "@playwright/test";
import cheerio from "cheerio";
import { load } from "cheerio";
import cp from "child_process";
import prettier from "prettier";

Expand Down Expand Up @@ -228,16 +228,18 @@ export async function getHtml(page: Page, selector?: string) {
}

export function getElement(source: string, selector: string) {
let el = cheerio(selector, source);
let $ = load(source);
let el = $(selector);
if (!el.length) {
throw new Error(`No element matches selector "${selector}"`);
}
return el;
}

export function selectHtml(source: string, selector: string) {
let el = getElement(source, selector);
return prettyHtml(cheerio.html(el)).trim();
let $ = load(source);
let el = $(selector);
return prettyHtml($.html(el)).trim();
}

export function selectText(source: string, selector: string) {
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.17.11",
"@types/testing-library__jest-dom": "^5.14.9",
"cheerio": "1.0.0-rc.12",
"cheerio": "^1.0.0",
"compression": "^1.7.4",
"cross-spawn": "^7.0.3",
"fs-extra": "^11.1.1",
Expand Down

0 comments on commit ba7bbd5

Please sign in to comment.