Skip to content

Commit

Permalink
fix: fix compatibility with Puppeteer v21 (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Oct 1, 2023
1 parent 3fb7702 commit 5cfee1f
Show file tree
Hide file tree
Showing 48 changed files with 8,829 additions and 12,905 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
jestPuppeteer: "readonly",
page: "readonly",
},

overrides: [
{
files: ["*.test.?(m|t)js"],
Expand All @@ -37,6 +38,9 @@ module.exports = {
tsconfigRootDir: __dirname,
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/no-explicit-any": "warn",
},
},
],
};
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"useWorkspaces": true,
"version": "9.0.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
21,374 changes: 8,641 additions & 12,733 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
},
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.59",
"@swc/jest": "^0.2.26",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"conventional-github-releaser": "^3.1.5",
"cross-env": "^7.0.3",
"eslint": "^8.41.0",
"eslint-plugin-jest": "^27.2.1",
"eslint": "^8.50.0",
"eslint-plugin-jest": "^27.4.2",
"express": "^4.18.2",
"jest": "^29.5.0",
"lerna": "^6.6.2",
"prettier": "^2.8.8",
"puppeteer": "^20.3.0",
"typescript": "^5.0.4"
"jest": "^29.7.0",
"lerna": "^7.3.0",
"prettier": "^3.0.3",
"puppeteer": "^21.3.6",
"typescript": "^5.2.2"
},
"name": "jest-puppeteer",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-puppeteer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ import { join } from "node:path";

await expect(page).toUploadFile(
'input[type="file"]',
join(__dirname, "file.txt")
join(__dirname, "file.txt"),
);
```

Expand Down
1 change: 1 addition & 0 deletions packages/expect-puppeteer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports = {
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest"],
},
testTimeout: 10000,
};
8 changes: 4 additions & 4 deletions packages/expect-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"build": "rollup -c"
},
"devDependencies": {
"puppeteer": "^20.3.0",
"rollup": "^3.23.0",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-swc3": "^0.8.1"
"puppeteer": "^21.3.6",
"rollup": "^3.29.4",
"rollup-plugin-dts": "^6.0.2",
"rollup-plugin-swc3": "^0.10.1"
}
}
9 changes: 5 additions & 4 deletions packages/expect-puppeteer/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { swc, defineRollupSwcOption } from "rollup-plugin-swc3";
import dts from "rollup-plugin-dts";
import * as url from "node:url";

const bundle = (config) => ({
input: "src/index.ts",
Expand All @@ -12,14 +13,14 @@ const bundle = (config) => ({
const swcPlugin = swc(
defineRollupSwcOption({
jsc: {
baseUrl: url.fileURLToPath(new URL(".", import.meta.url)),
parser: {
syntax: "typescript",
},
target: "es2022",
externalHelpers: false,
},
env: {
targets: "node 16",
},
})
}),
);

export default [
Expand Down
8 changes: 4 additions & 4 deletions packages/expect-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-namespace, no-use-before-define, no-restricted-syntax, no-await-in-loop */
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-namespace, no-use-before-define, no-restricted-syntax, no-await-in-loop, @typescript-eslint/no-unused-vars */
import {
checkIsPuppeteerInstance,
checkIsElementHandle,
Expand Down Expand Up @@ -100,7 +100,7 @@ const jestExpect = global.expect as JestExpect;

const wrapMatcher = <TPage extends PuppeteerInstance>(
matcher: Matcher<TPage>,
instance: PuppeteerInstance
instance: PuppeteerInstance,
) => {
return async function throwingMatcher(...args: any[]) {

Check warning on line 105 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (16)

Unexpected any. Specify a different type

Check warning on line 105 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (18)

Unexpected any. Specify a different type

Check warning on line 105 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (latest)

Unexpected any. Specify a different type
jestExpect.getState().assertionCalls += 1;
Expand All @@ -116,7 +116,7 @@ const wrapMatcher = <TPage extends PuppeteerInstance>(

const createExpect = <T extends PuppeteerInstance>(
instance: T,
matchers: MatcherSet<T>
matchers: MatcherSet<T>,
) => {
const expectation = {
not: {} as Record<string, any>,

Check warning on line 122 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (16)

Unexpected any. Specify a different type

Check warning on line 122 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (18)

Unexpected any. Specify a different type

Check warning on line 122 in packages/expect-puppeteer/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (latest)

Unexpected any. Specify a different type
Expand All @@ -134,7 +134,7 @@ const createExpect = <T extends PuppeteerInstance>(
};

const expectPuppeteerInstance = <TInstance extends PuppeteerInstance>(
actual: TInstance
actual: TInstance,
): PuppeteerMatchers => {
if (checkIsPage(actual)) {
return createExpect(actual, pageMatchers) as PuppeteerMatchers;
Expand Down
8 changes: 4 additions & 4 deletions packages/expect-puppeteer/src/matchers/getElementFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type GetElementOptions = {
export async function getElementFactory(
instance: PuppeteerInstance,
selector: Selector,
options: GetElementOptions
options: GetElementOptions,
) {
const { text: searchExpr, visible = false } = options;

Expand All @@ -24,7 +24,7 @@ export async function getElementFactory(
const { text, regexp } = serializeSearchExpression(searchExpr);

const parseSearchExpressionHandle = await evaluateParseSearchExpression(
ctx.page
ctx.page,
);

const getElementArgs = [
Expand All @@ -43,9 +43,9 @@ export async function getElementFactory(
regexp: string | null,
visible: boolean,
parseSearchExpression: (
expr: SerializedSearchExpression
expr: SerializedSearchExpression,
) => ((value: string) => boolean) | null,
type: "element" | "positive" | "negative"
type: "element" | "positive" | "negative",
) => {
const hasVisibleBoundingBox = (element: Element): boolean => {
const rect = element.getBoundingClientRect();
Expand Down
10 changes: 5 additions & 5 deletions packages/expect-puppeteer/src/matchers/matchTextContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function matchTextContent(
instance: PuppeteerInstance,
matcher: SearchExpression,
options: MatchTextContentOptions,
type: "positive" | "negative"
type: "positive" | "negative",
) {
const { traverseShadowRoots = false, ...otherOptions } = options;
const frameOptions = defaultOptions(otherOptions);
Expand All @@ -25,7 +25,7 @@ export async function matchTextContent(
const { text, regexp } = serializeSearchExpression(matcher);

const parseSearchExpressionHandle = await evaluateParseSearchExpression(
ctx.page
ctx.page,
);

await ctx.page.waitForFunction(
Expand All @@ -35,7 +35,7 @@ export async function matchTextContent(
regexp,
traverseShadowRoots,
parseSearchExpression,
type
type,
) => {
const checkNodeIsElement = (node: Node): node is Element => {
return node.nodeType === Node.ELEMENT_NODE;
Expand All @@ -52,7 +52,7 @@ export async function matchTextContent(
function getShadowTextContent(node: Node) {
const walker = document.createTreeWalker(
node,
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
);
let result = "";
let currentNode = walker.nextNode();
Expand Down Expand Up @@ -110,6 +110,6 @@ export async function matchTextContent(
regexp,
traverseShadowRoots,
parseSearchExpressionHandle,
type
type,
);
}
6 changes: 3 additions & 3 deletions packages/expect-puppeteer/src/matchers/notToMatchElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ export type NotToMatchElementOptions = GetElementOptions & Options;
export async function notToMatchElement(
instance: PuppeteerInstance,
selector: Selector | string,
options: NotToMatchElementOptions = {}
options: NotToMatchElementOptions = {},
) {
const { text, visible, ...otherOptions } = options;
const frameOptions = defaultOptions(otherOptions);
const rSelector = resolveSelector(selector);
const [getElement, getElementArgs, ctx] = await getElementFactory(
instance,
rSelector,
{ text, visible }
{ text, visible },
);

try {
await ctx.page.waitForFunction(
getElement,
frameOptions,
...getElementArgs,
"negative" as const
"negative" as const,
);
} catch (error: any) {
throw enhanceError(error, `${getSelectorMessage(rSelector, text)} found`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("not.toMatchTextContent", () => {
expect(error.stack).toMatch(resolve(__filename));
}
});
}
},
);

describe("ElementHandle", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type NotToMatchOptions = MatchTextContentOptions;
export async function notToMatchTextContent(
instance: PuppeteerInstance,
matcher: SearchExpression,
options: NotToMatchOptions = {}
options: NotToMatchOptions = {},
) {
try {
await matchTextContent(instance, matcher, options, "negative");
Expand Down
4 changes: 2 additions & 2 deletions packages/expect-puppeteer/src/matchers/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function goToPage(
page: Page,
route: string,
isFrame: boolean,
cb: (arg0: { currentPage: Page | Frame }) => void
cb: (arg0: { currentPage: Page | Frame }) => void,
) {
let currentPage: Page | Frame = page;
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}/${route}`);
Expand All @@ -31,7 +31,7 @@ async function goToPage(

export const setupPage = (
instanceType: string,
cb: (arg0: { currentPage: Page | Frame }) => void
cb: (arg0: { currentPage: Page | Frame }) => void,
) => {
beforeEach(async () => {
if (instanceType === "Page") {
Expand Down
20 changes: 10 additions & 10 deletions packages/expect-puppeteer/src/matchers/toClick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("toClick", () => {
await expect(instance).toClick('a[href="/page2.html"]');
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -28,7 +28,7 @@ describe("toClick", () => {
});
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -40,7 +40,7 @@ describe("toClick", () => {
});
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -49,7 +49,7 @@ describe("toClick", () => {
await expect(instance).toClick("a", { text: "Page 2" });
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -60,11 +60,11 @@ describe("toClick", () => {
value: "//a",
type: "xpath",
},
{ text: "Page 2" }
{ text: "Page 2" },
);
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -75,11 +75,11 @@ describe("toClick", () => {
value: "a",
type: "css",
},
{ text: "Page 2" }
{ text: "Page 2" },
);
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});
Expand All @@ -101,7 +101,7 @@ describe("toClick", () => {
try {
await expect(instance).toClick(
{ value: "//a", type: "xpath" },
{ text: "Nop" }
{ text: "Nop" },
);
} catch (error: any) {
expect(error.message).toMatch('Element //a (text: "Nop") not found');
Expand All @@ -115,7 +115,7 @@ describe("toClick", () => {
try {
await expect(instance).toClick(
{ value: "a", type: "css" },
{ text: "Nop" }
{ text: "Nop" },
);
} catch (error: any) {
expect(error.message).toMatch('Element a (text: "Nop") not found');
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-puppeteer/src/matchers/toClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ToClickOptions = ToMatchElementOptions & ClickOptions;
export async function toClick(
instance: PuppeteerInstance,
selector: Selector | string,
options: ToClickOptions = {}
options: ToClickOptions = {},
) {
const { delay, button, clickCount, offset, ...otherOptions } = options;
const element = await toMatchElement(instance, selector, otherOptions);
Expand Down
Loading

0 comments on commit 5cfee1f

Please sign in to comment.