Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support puppeteer v23 #588

Merged
merged 6 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
screenshots/
screenshots/
.nx/
19,979 changes: 2,715 additions & 17,264 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 @@ -14,21 +14,21 @@
"release-canary": "npm run build && lerna publish --canary --dist-tag canary"
},
"devDependencies": {
"@swc/cli": "^0.1.63",
"@swc/core": "^1.3.99",
"@swc/jest": "^0.2.29",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.11",
"@swc/jest": "^0.2.36",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"conventional-github-releaser": "^3.1.5",
"cross-env": "^7.0.3",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^27.6.0",
"express": "^4.18.2",
"eslint-plugin-jest": "^28.8.0",
"express": "^4.19.2",
"jest": "^29.7.0",
"lerna": "^7.4.2",
"prettier": "^3.1.0",
"puppeteer": "^22.0.0",
"typescript": "^5.3.2"
"lerna": "^8.1.8",
"prettier": "^3.3.3",
"puppeteer": "^23.1.0",
"typescript": "^5.5.4"
},
"name": "jest-puppeteer",
"engines": {
Expand Down
1 change: 0 additions & 1 deletion packages/expect-puppeteer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ 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": "^22.0.0",
"rollup": "^4.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-swc3": "^0.10.4"
"puppeteer": "^23.1.0",
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2"
}
}
17 changes: 7 additions & 10 deletions packages/expect-puppeteer/src/matchers/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
import type { Page, Frame } from "puppeteer";

function waitForFrame(page: Page) {
let fulfill: (value: Page | Frame) => void;
const promise = new Promise<Page | Frame>((resolve) => {
fulfill = resolve;
return new Promise<Frame>((resolve) => {
function checkFrame() {
const frame = page.frames().find((f) => f.parentFrame() !== null);
if (frame) resolve(frame);
else page.once(`frameattached`, checkFrame);
}
checkFrame();
});
function checkFrame() {
const frame = page.frames().find((f) => f.parentFrame() !== null);
if (frame) fulfill(frame);
else page.once(`frameattached`, checkFrame);
}
checkFrame();
return promise;
}

async function goToPage(
Expand Down
26 changes: 2 additions & 24 deletions packages/expect-puppeteer/src/matchers/toClick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ describe("toClick", () => {

describe.each(["Page", "Frame"])("%s", (instanceType) => {
let instance: Page | Frame;

setupPage(instanceType, ({ currentPage }) => {
instance = currentPage;
});

it("should click using selector", async () => {
await expect(instance).toClick('a[href="/page2.html"]');
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should click using xpath selector", async () => {
Expand All @@ -27,10 +25,6 @@ describe("toClick", () => {
type: "xpath",
});
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should click using css selector with object param", async () => {
Expand All @@ -39,19 +33,11 @@ describe("toClick", () => {
type: "css",
});
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should click using text", async () => {
await expect(instance).toClick("a", { text: "Page 2" });
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should click using text with xpath selector", async () => {
Expand All @@ -63,10 +49,6 @@ describe("toClick", () => {
{ text: "Page 2" },
);
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should click using text with css selector", async () => {
Expand All @@ -78,10 +60,6 @@ describe("toClick", () => {
{ text: "Page 2" },
);
await instance.waitForNavigation();
const pathname = await instance.evaluate(
() => document.location.pathname,
);
expect(pathname).toBe("/page2.html");
});

it("should return an error if element is not found", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-puppeteer/src/matchers/toFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function selectAll(element: ElementHandle<Element>) {
if (element.setSelectionRange) {
try {
element.setSelectionRange(0, element.value.length);
} catch (e) {
} catch {
// setSelectionRange throws an error for inputs: number/date/time/etc
// we can just focus them and the content will be selected
element.focus();
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"@types/cwd": "^0.10.2",
"@types/prompts": "^2.4.9",
"@types/wait-on": "^5.3.4",
"rollup": "^4.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-swc3": "^0.10.4"
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2"
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-environment-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@types/jest": "^29.5.9",
"rollup": "^4.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-swc3": "^0.10.4"
"@types/jest": "^29.5.12",
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2"
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-environment-puppeteer/src/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type { PuppeteerNode, Browser } from "puppeteer";

const getPuppeteer = (): PuppeteerNode => {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require("puppeteer");
} catch (e) {
} catch {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require("puppeteer-core");
}
};
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-environment-puppeteer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ const createContext = async (global: StrictGlobal) => {

const closeContext = async (global: StrictGlobal) => {
if (!global.context) return;
if (global.context.isIncognito()) {
const browser = getBrowser(global);
// If a custom context was created, close it
if (global.context !== browser.defaultBrowserContext()) {
await global.context.close();
}
global.context = undefined;
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"jest-environment-puppeteer": "^10.0.1"
},
"devDependencies": {
"rollup": "^4.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-swc3": "^0.10.4"
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2"
}
}
6 changes: 3 additions & 3 deletions packages/spawnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"devDependencies": {
"@types/exit": "^0.1.33",
"@types/signal-exit": "^3.0.4",
"rollup": "^4.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-swc3": "^0.10.4"
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2"
},
"dependencies": {
"signal-exit": "^4.1.0",
Expand Down
Loading