Skip to content

Commit 5cfee1f

Browse files
authored
fix: fix compatibility with Puppeteer v21 (#566)
1 parent 3fb7702 commit 5cfee1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+8829
-12905
lines changed

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
jestPuppeteer: "readonly",
1515
page: "readonly",
1616
},
17+
1718
overrides: [
1819
{
1920
files: ["*.test.?(m|t)js"],
@@ -37,6 +38,9 @@ module.exports = {
3738
tsconfigRootDir: __dirname,
3839
},
3940
plugins: ["@typescript-eslint"],
41+
rules: {
42+
"@typescript-eslint/no-explicit-any": "warn",
43+
},
4044
},
4145
],
4246
};

lerna.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"useWorkspaces": true,
32
"version": "9.0.0",
43
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
54
}

package-lock.json

+8,641-12,733
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
},
1616
"devDependencies": {
1717
"@swc/cli": "^0.1.62",
18-
"@swc/core": "^1.3.59",
19-
"@swc/jest": "^0.2.26",
20-
"@typescript-eslint/eslint-plugin": "^5.59.7",
21-
"@typescript-eslint/parser": "^5.59.7",
18+
"@swc/core": "^1.3.90",
19+
"@swc/jest": "^0.2.29",
20+
"@typescript-eslint/eslint-plugin": "^6.7.3",
21+
"@typescript-eslint/parser": "^6.7.3",
2222
"conventional-github-releaser": "^3.1.5",
2323
"cross-env": "^7.0.3",
24-
"eslint": "^8.41.0",
25-
"eslint-plugin-jest": "^27.2.1",
24+
"eslint": "^8.50.0",
25+
"eslint-plugin-jest": "^27.4.2",
2626
"express": "^4.18.2",
27-
"jest": "^29.5.0",
28-
"lerna": "^6.6.2",
29-
"prettier": "^2.8.8",
30-
"puppeteer": "^20.3.0",
31-
"typescript": "^5.0.4"
27+
"jest": "^29.7.0",
28+
"lerna": "^7.3.0",
29+
"prettier": "^3.0.3",
30+
"puppeteer": "^21.3.6",
31+
"typescript": "^5.2.2"
3232
},
3333
"name": "jest-puppeteer",
3434
"engines": {

packages/expect-puppeteer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ import { join } from "node:path";
204204

205205
await expect(page).toUploadFile(
206206
'input[type="file"]',
207-
join(__dirname, "file.txt")
207+
join(__dirname, "file.txt"),
208208
);
209209
```
210210

packages/expect-puppeteer/jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
transform: {
44
"^.+\\.(t|j)sx?$": ["@swc/jest"],
55
},
6+
testTimeout: 10000,
67
};

packages/expect-puppeteer/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"build": "rollup -c"
4545
},
4646
"devDependencies": {
47-
"puppeteer": "^20.3.0",
48-
"rollup": "^3.23.0",
49-
"rollup-plugin-dts": "^5.3.0",
50-
"rollup-plugin-swc3": "^0.8.1"
47+
"puppeteer": "^21.3.6",
48+
"rollup": "^3.29.4",
49+
"rollup-plugin-dts": "^6.0.2",
50+
"rollup-plugin-swc3": "^0.10.1"
5151
}
5252
}

packages/expect-puppeteer/rollup.config.mjs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { swc, defineRollupSwcOption } from "rollup-plugin-swc3";
22
import dts from "rollup-plugin-dts";
3+
import * as url from "node:url";
34

45
const bundle = (config) => ({
56
input: "src/index.ts",
@@ -12,14 +13,14 @@ const bundle = (config) => ({
1213
const swcPlugin = swc(
1314
defineRollupSwcOption({
1415
jsc: {
16+
baseUrl: url.fileURLToPath(new URL(".", import.meta.url)),
1517
parser: {
1618
syntax: "typescript",
1719
},
20+
target: "es2022",
21+
externalHelpers: false,
1822
},
19-
env: {
20-
targets: "node 16",
21-
},
22-
})
23+
}),
2324
);
2425

2526
export default [

packages/expect-puppeteer/src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-namespace, no-use-before-define, no-restricted-syntax, no-await-in-loop */
1+
/* 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 */
22
import {
33
checkIsPuppeteerInstance,
44
checkIsElementHandle,
@@ -100,7 +100,7 @@ const jestExpect = global.expect as JestExpect;
100100

101101
const wrapMatcher = <TPage extends PuppeteerInstance>(
102102
matcher: Matcher<TPage>,
103-
instance: PuppeteerInstance
103+
instance: PuppeteerInstance,
104104
) => {
105105
return async function throwingMatcher(...args: any[]) {
106106
jestExpect.getState().assertionCalls += 1;
@@ -116,7 +116,7 @@ const wrapMatcher = <TPage extends PuppeteerInstance>(
116116

117117
const createExpect = <T extends PuppeteerInstance>(
118118
instance: T,
119-
matchers: MatcherSet<T>
119+
matchers: MatcherSet<T>,
120120
) => {
121121
const expectation = {
122122
not: {} as Record<string, any>,
@@ -134,7 +134,7 @@ const createExpect = <T extends PuppeteerInstance>(
134134
};
135135

136136
const expectPuppeteerInstance = <TInstance extends PuppeteerInstance>(
137-
actual: TInstance
137+
actual: TInstance,
138138
): PuppeteerMatchers => {
139139
if (checkIsPage(actual)) {
140140
return createExpect(actual, pageMatchers) as PuppeteerMatchers;

packages/expect-puppeteer/src/matchers/getElementFactory.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type GetElementOptions = {
1515
export async function getElementFactory(
1616
instance: PuppeteerInstance,
1717
selector: Selector,
18-
options: GetElementOptions
18+
options: GetElementOptions,
1919
) {
2020
const { text: searchExpr, visible = false } = options;
2121

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

2626
const parseSearchExpressionHandle = await evaluateParseSearchExpression(
27-
ctx.page
27+
ctx.page,
2828
);
2929

3030
const getElementArgs = [
@@ -43,9 +43,9 @@ export async function getElementFactory(
4343
regexp: string | null,
4444
visible: boolean,
4545
parseSearchExpression: (
46-
expr: SerializedSearchExpression
46+
expr: SerializedSearchExpression,
4747
) => ((value: string) => boolean) | null,
48-
type: "element" | "positive" | "negative"
48+
type: "element" | "positive" | "negative",
4949
) => {
5050
const hasVisibleBoundingBox = (element: Element): boolean => {
5151
const rect = element.getBoundingClientRect();

packages/expect-puppeteer/src/matchers/matchTextContent.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function matchTextContent(
1515
instance: PuppeteerInstance,
1616
matcher: SearchExpression,
1717
options: MatchTextContentOptions,
18-
type: "positive" | "negative"
18+
type: "positive" | "negative",
1919
) {
2020
const { traverseShadowRoots = false, ...otherOptions } = options;
2121
const frameOptions = defaultOptions(otherOptions);
@@ -25,7 +25,7 @@ export async function matchTextContent(
2525
const { text, regexp } = serializeSearchExpression(matcher);
2626

2727
const parseSearchExpressionHandle = await evaluateParseSearchExpression(
28-
ctx.page
28+
ctx.page,
2929
);
3030

3131
await ctx.page.waitForFunction(
@@ -35,7 +35,7 @@ export async function matchTextContent(
3535
regexp,
3636
traverseShadowRoots,
3737
parseSearchExpression,
38-
type
38+
type,
3939
) => {
4040
const checkNodeIsElement = (node: Node): node is Element => {
4141
return node.nodeType === Node.ELEMENT_NODE;
@@ -52,7 +52,7 @@ export async function matchTextContent(
5252
function getShadowTextContent(node: Node) {
5353
const walker = document.createTreeWalker(
5454
node,
55-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
55+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
5656
);
5757
let result = "";
5858
let currentNode = walker.nextNode();
@@ -110,6 +110,6 @@ export async function matchTextContent(
110110
regexp,
111111
traverseShadowRoots,
112112
parseSearchExpressionHandle,
113-
type
113+
type,
114114
);
115115
}

packages/expect-puppeteer/src/matchers/notToMatchElement.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ export type NotToMatchElementOptions = GetElementOptions & Options;
2121
export async function notToMatchElement(
2222
instance: PuppeteerInstance,
2323
selector: Selector | string,
24-
options: NotToMatchElementOptions = {}
24+
options: NotToMatchElementOptions = {},
2525
) {
2626
const { text, visible, ...otherOptions } = options;
2727
const frameOptions = defaultOptions(otherOptions);
2828
const rSelector = resolveSelector(selector);
2929
const [getElement, getElementArgs, ctx] = await getElementFactory(
3030
instance,
3131
rSelector,
32-
{ text, visible }
32+
{ text, visible },
3333
);
3434

3535
try {
3636
await ctx.page.waitForFunction(
3737
getElement,
3838
frameOptions,
3939
...getElementArgs,
40-
"negative" as const
40+
"negative" as const,
4141
);
4242
} catch (error: any) {
4343
throw enhanceError(error, `${getSelectorMessage(rSelector, text)} found`);

packages/expect-puppeteer/src/matchers/notToMatchTextContent.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("not.toMatchTextContent", () => {
3434
expect(error.stack).toMatch(resolve(__filename));
3535
}
3636
});
37-
}
37+
},
3838
);
3939

4040
describe("ElementHandle", () => {

packages/expect-puppeteer/src/matchers/notToMatchTextContent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type NotToMatchOptions = MatchTextContentOptions;
66
export async function notToMatchTextContent(
77
instance: PuppeteerInstance,
88
matcher: SearchExpression,
9-
options: NotToMatchOptions = {}
9+
options: NotToMatchOptions = {},
1010
) {
1111
try {
1212
await matchTextContent(instance, matcher, options, "negative");

packages/expect-puppeteer/src/matchers/test-util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function goToPage(
1919
page: Page,
2020
route: string,
2121
isFrame: boolean,
22-
cb: (arg0: { currentPage: Page | Frame }) => void
22+
cb: (arg0: { currentPage: Page | Frame }) => void,
2323
) {
2424
let currentPage: Page | Frame = page;
2525
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}/${route}`);
@@ -31,7 +31,7 @@ async function goToPage(
3131

3232
export const setupPage = (
3333
instanceType: string,
34-
cb: (arg0: { currentPage: Page | Frame }) => void
34+
cb: (arg0: { currentPage: Page | Frame }) => void,
3535
) => {
3636
beforeEach(async () => {
3737
if (instanceType === "Page") {

packages/expect-puppeteer/src/matchers/toClick.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("toClick", () => {
1616
await expect(instance).toClick('a[href="/page2.html"]');
1717
await instance.waitForNavigation();
1818
const pathname = await instance.evaluate(
19-
() => document.location.pathname
19+
() => document.location.pathname,
2020
);
2121
expect(pathname).toBe("/page2.html");
2222
});
@@ -28,7 +28,7 @@ describe("toClick", () => {
2828
});
2929
await instance.waitForNavigation();
3030
const pathname = await instance.evaluate(
31-
() => document.location.pathname
31+
() => document.location.pathname,
3232
);
3333
expect(pathname).toBe("/page2.html");
3434
});
@@ -40,7 +40,7 @@ describe("toClick", () => {
4040
});
4141
await instance.waitForNavigation();
4242
const pathname = await instance.evaluate(
43-
() => document.location.pathname
43+
() => document.location.pathname,
4444
);
4545
expect(pathname).toBe("/page2.html");
4646
});
@@ -49,7 +49,7 @@ describe("toClick", () => {
4949
await expect(instance).toClick("a", { text: "Page 2" });
5050
await instance.waitForNavigation();
5151
const pathname = await instance.evaluate(
52-
() => document.location.pathname
52+
() => document.location.pathname,
5353
);
5454
expect(pathname).toBe("/page2.html");
5555
});
@@ -60,11 +60,11 @@ describe("toClick", () => {
6060
value: "//a",
6161
type: "xpath",
6262
},
63-
{ text: "Page 2" }
63+
{ text: "Page 2" },
6464
);
6565
await instance.waitForNavigation();
6666
const pathname = await instance.evaluate(
67-
() => document.location.pathname
67+
() => document.location.pathname,
6868
);
6969
expect(pathname).toBe("/page2.html");
7070
});
@@ -75,11 +75,11 @@ describe("toClick", () => {
7575
value: "a",
7676
type: "css",
7777
},
78-
{ text: "Page 2" }
78+
{ text: "Page 2" },
7979
);
8080
await instance.waitForNavigation();
8181
const pathname = await instance.evaluate(
82-
() => document.location.pathname
82+
() => document.location.pathname,
8383
);
8484
expect(pathname).toBe("/page2.html");
8585
});
@@ -101,7 +101,7 @@ describe("toClick", () => {
101101
try {
102102
await expect(instance).toClick(
103103
{ value: "//a", type: "xpath" },
104-
{ text: "Nop" }
104+
{ text: "Nop" },
105105
);
106106
} catch (error: any) {
107107
expect(error.message).toMatch('Element //a (text: "Nop") not found');
@@ -115,7 +115,7 @@ describe("toClick", () => {
115115
try {
116116
await expect(instance).toClick(
117117
{ value: "a", type: "css" },
118-
{ text: "Nop" }
118+
{ text: "Nop" },
119119
);
120120
} catch (error: any) {
121121
expect(error.message).toMatch('Element a (text: "Nop") not found');

packages/expect-puppeteer/src/matchers/toClick.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type ToClickOptions = ToMatchElementOptions & ClickOptions;
77
export async function toClick(
88
instance: PuppeteerInstance,
99
selector: Selector | string,
10-
options: ToClickOptions = {}
10+
options: ToClickOptions = {},
1111
) {
1212
const { delay, button, clickCount, offset, ...otherOptions } = options;
1313
const element = await toMatchElement(instance, selector, otherOptions);

0 commit comments

Comments
 (0)