From fd350fbc4ed2a2c50b49f555d59d968c1ff0b484 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 01:59:54 +0530 Subject: [PATCH 1/8] Add puppeteer --- package-lock.json | 193 +++++++++++++++++++++++++++++----------------- package.json | 1 + 2 files changed, 124 insertions(+), 70 deletions(-) diff --git a/package-lock.json b/package-lock.json index e2702b1d36f..1dcfc43a196 100644 --- a/package-lock.json +++ b/package-lock.json @@ -78,6 +78,7 @@ "postcss-nested": "6.0.1", "postcss-preset-env": "9.2.0", "prettier": "3.0.3", + "puppeteer": "21.5.0", "react-test-renderer": "18.2.0", "rtlcss-webpack-plugin": "4.0.7", "semver": "7.5.4", @@ -4442,19 +4443,18 @@ } }, "node_modules/@puppeteer/browsers": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-1.7.0.tgz", - "integrity": "sha512-sl7zI0IkbQGak/+IE3VEEZab5SSOlI5F6558WvzWGC1n3+C722rfewC1ZIkcF9dsoGSsxhsONoseVlNQG4wWvQ==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-1.8.0.tgz", + "integrity": "sha512-TkRHIV6k2D8OlUe8RtG+5jgOF/H98Myx0M6AOafC8DdNVOFiBSFa5cpRDtpm8LXOa9sVwe0+e6Q3FC56X/DZfg==", "dev": true, - "peer": true, "dependencies": { "debug": "4.3.4", "extract-zip": "2.0.1", "progress": "2.0.3", - "proxy-agent": "6.3.0", + "proxy-agent": "6.3.1", "tar-fs": "3.0.4", "unbzip2-stream": "1.4.3", - "yargs": "17.7.1" + "yargs": "17.7.2" }, "bin": { "browsers": "lib/cjs/main-cli.js" @@ -4463,12 +4463,23 @@ "node": ">=16.3.0" } }, + "node_modules/@puppeteer/browsers/node_modules/agent-base": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", + "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", + "dev": true, + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/@puppeteer/browsers/node_modules/extract-zip": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", "dev": true, - "peer": true, "dependencies": { "debug": "^4.1.1", "get-stream": "^5.1.0", @@ -4484,25 +4495,60 @@ "@types/yauzl": "^2.9.1" } }, - "node_modules/@puppeteer/browsers/node_modules/yargs": { - "version": "17.7.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.1.tgz", - "integrity": "sha512-cwiTb08Xuv5fqF4AovYacTFNxk62th7LKJ6BL9IGUpTJrWoU7/7WdQGTP2SjKf1dUNBGzDd28p/Yfs/GI6JrLw==", + "node_modules/@puppeteer/browsers/node_modules/http-proxy-agent": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz", + "integrity": "sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==", "dev": true, - "peer": true, "dependencies": { - "cliui": "^8.0.1", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.1.1" + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@puppeteer/browsers/node_modules/https-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", + "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", + "dev": true, + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@puppeteer/browsers/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "dev": true, "engines": { "node": ">=12" } }, + "node_modules/@puppeteer/browsers/node_modules/proxy-agent": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.3.1.tgz", + "integrity": "sha512-Rb5RVBy1iyqOtNl15Cw/llpeLH8bsb37gM1FUfKQ+Wck6xHlbAhWGUFiTRHtkjqGTA5pSHz6+0hrPW/oECihPQ==", + "dev": true, + "dependencies": { + "agent-base": "^7.0.2", + "debug": "^4.3.4", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", + "lru-cache": "^7.14.1", + "pac-proxy-agent": "^7.0.1", + "proxy-from-env": "^1.1.0", + "socks-proxy-agent": "^8.0.2" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/@radix-ui/primitive": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.0.0.tgz", @@ -10669,13 +10715,13 @@ } }, "node_modules/chromium-bidi": { - "version": "0.4.22", - "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.4.22.tgz", - "integrity": "sha512-wR7Y9Ioez+cNXT4ZP7VNM1HRTljpNnMSLw4/RnwhhZUP4yCU7kIQND00YiktuHekch68jklGPK1q9Jkb29+fQg==", + "version": "0.4.33", + "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.4.33.tgz", + "integrity": "sha512-IxoFM5WGQOIAd95qrSXzJUv4eXIrh+RvU3rwwqIiwYuvfE7U/Llj4fejbsJnjJMUYCuGtVQsY2gv7oGl4aTNSQ==", "dev": true, - "peer": true, "dependencies": { - "mitt": "3.0.1" + "mitt": "3.0.1", + "urlpattern-polyfill": "9.0.0" }, "peerDependencies": { "devtools-protocol": "*" @@ -12566,11 +12612,10 @@ "integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==" }, "node_modules/devtools-protocol": { - "version": "0.0.1159816", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1159816.tgz", - "integrity": "sha512-2cZlHxC5IlgkIWe2pSDmCrDiTzbSJWywjbDDnupOImEBcG31CQgBLV8wWE+5t+C4rimcjHsbzy7CBzf9oFjboA==", - "dev": true, - "peer": true + "version": "0.0.1203626", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1203626.tgz", + "integrity": "sha512-nEzHZteIUZfGCZtTiS1fRpC8UZmsfD1SiyPvaUNvS13dvKf666OAm8YTi0+Ca3n1nLEyu49Cy4+dPWpaHFJk9g==", + "dev": true }, "node_modules/diff": { "version": "4.0.2", @@ -21621,8 +21666,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==", - "dev": true, - "peer": true + "dev": true }, "node_modules/mixin-object": { "version": "2.0.1", @@ -22816,9 +22860,9 @@ } }, "node_modules/pac-proxy-agent": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.0.tgz", - "integrity": "sha512-t4tRAMx0uphnZrio0S0Jw9zg3oDbz1zVhQ/Vy18FjLfP1XOLNUEjaVxYCYRI6NS+BsMBXKIzV6cTLOkO9AtywA==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.1.tgz", + "integrity": "sha512-ASV8yU4LLKBAjqIPMbrgtaKIvxQri/yh2OpI+S6hVa9JRkUI3Y3NPFbfngDtY7oFtSMD3w31Xns89mDa3Feo5A==", "dev": true, "dependencies": { "@tootallnate/quickjs-emscripten": "^0.23.0", @@ -22826,9 +22870,9 @@ "debug": "^4.3.4", "get-uri": "^6.0.1", "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", "pac-resolver": "^7.0.0", - "socks-proxy-agent": "^8.0.1" + "socks-proxy-agent": "^8.0.2" }, "engines": { "node": ">= 14" @@ -22860,9 +22904,9 @@ } }, "node_modules/pac-proxy-agent/node_modules/https-proxy-agent": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.1.tgz", - "integrity": "sha512-Eun8zV0kcYS1g19r78osiQLEFIRspRUDd9tIfBCTBPBeMieF/EsJNL8VI3xOIdYRDEkjQnqOYPsZ2DsWsVsFwQ==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", + "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", "dev": true, "dependencies": { "agent-base": "^7.0.2", @@ -24844,34 +24888,32 @@ } }, "node_modules/puppeteer": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-21.1.1.tgz", - "integrity": "sha512-2TLntjGA4qLrI9/8N0UK/5OoZJ2Ue7QgphN2SD+RsaHiha12AEiVyMGsB+i6LY1IoPAtEgYIjblQ7lw3kWDNRw==", + "version": "21.5.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-21.5.0.tgz", + "integrity": "sha512-prvy9rdauyIaaEgefQRcw9zhQnYQbl8O1Gj5VJazKJ7kwNx703+Paw/1bwA+b96jj/S+r55hrmF5SfiEG5PUcg==", "dev": true, "hasInstallScript": true, - "peer": true, "dependencies": { - "@puppeteer/browsers": "1.7.0", - "cosmiconfig": "8.2.0", - "puppeteer-core": "21.1.1" + "@puppeteer/browsers": "1.8.0", + "cosmiconfig": "8.3.6", + "puppeteer-core": "21.5.0" }, "engines": { "node": ">=16.3.0" } }, "node_modules/puppeteer-core": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-21.1.1.tgz", - "integrity": "sha512-Tlcajcf44zwfa9Sbwv3T8BtaNMJ69wtpHIxwl2NOBTyTK3D1wppQovXTjfw0TDOm3a16eCfQ+5BMi3vRQ4kuAQ==", + "version": "21.5.0", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-21.5.0.tgz", + "integrity": "sha512-qG0RJ6qKgFz09UUZxDB9IcyTJGypQXMuE8WmEoHk7kgjutmRiOVv5RgsyUkY67AxDdBWx21bn1PHHRJnO/6b4A==", "dev": true, - "peer": true, "dependencies": { - "@puppeteer/browsers": "1.7.0", - "chromium-bidi": "0.4.22", + "@puppeteer/browsers": "1.8.0", + "chromium-bidi": "0.4.33", "cross-fetch": "4.0.0", "debug": "4.3.4", - "devtools-protocol": "0.0.1159816", - "ws": "8.13.0" + "devtools-protocol": "0.0.1203626", + "ws": "8.14.2" }, "engines": { "node": ">=16.3.0" @@ -24881,19 +24923,17 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, - "peer": true + "dev": true }, "node_modules/puppeteer/node_modules/cosmiconfig": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.2.0.tgz", - "integrity": "sha512-3rTMnFJA1tCOPwRxtgF4wd7Ab2qvDbL8jX+3smjIbS4HlZBagTlpERbdN7iAbWlrfxE3M8c27kTwTawQ7st+OQ==", + "version": "8.3.6", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", + "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", "dev": true, - "peer": true, "dependencies": { - "import-fresh": "^3.2.1", + "import-fresh": "^3.3.0", "js-yaml": "^4.1.0", - "parse-json": "^5.0.0", + "parse-json": "^5.2.0", "path-type": "^4.0.0" }, "engines": { @@ -24901,6 +24941,14 @@ }, "funding": { "url": "https://github.com/sponsors/d-fischer" + }, + "peerDependencies": { + "typescript": ">=4.9.5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } }, "node_modules/puppeteer/node_modules/js-yaml": { @@ -24908,7 +24956,6 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, - "peer": true, "dependencies": { "argparse": "^2.0.1" }, @@ -26929,12 +26976,12 @@ } }, "node_modules/socks-proxy-agent": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.1.tgz", - "integrity": "sha512-59EjPbbgg8U3x62hhKOFVAmySQUcfRQ4C7Q/D5sEHnZTQRrQlNKINks44DMR1gwXp0p4LaVIeccX2KHTTcHVqQ==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.2.tgz", + "integrity": "sha512-8zuqoLv1aP/66PHF5TqwJ7Czm3Yv32urJQHrVyhD7mmA6d61Zv8cIXQYPTWwmg6qlupnPvs/QKDmfa4P/qct2g==", "dev": true, "dependencies": { - "agent-base": "^7.0.1", + "agent-base": "^7.0.2", "debug": "^4.3.4", "socks": "^2.7.1" }, @@ -28602,6 +28649,12 @@ "requires-port": "^1.0.0" } }, + "node_modules/urlpattern-polyfill": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/urlpattern-polyfill/-/urlpattern-polyfill-9.0.0.tgz", + "integrity": "sha512-WHN8KDQblxd32odxeIgo83rdVDE2bvdkb86it7bMhYZwWKJz0+O0RK/eZiHYnM+zgt/U7hAHOlCQGfjjvSkw2g==", + "dev": true + }, "node_modules/use-callback-ref": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.0.tgz", @@ -29780,9 +29833,9 @@ } }, "node_modules/ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.14.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", + "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", "dev": true, "engines": { "node": ">=10.0.0" diff --git a/package.json b/package.json index fcff963b77e..f4399d0ab5a 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "postcss-nested": "6.0.1", "postcss-preset-env": "9.2.0", "prettier": "3.0.3", + "puppeteer": "21.5.0", "react-test-renderer": "18.2.0", "rtlcss-webpack-plugin": "4.0.7", "semver": "7.5.4", From b2e1c4cdca6ca2690ae74d20262360b8d4c10f9b Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:00:54 +0530 Subject: [PATCH 2/8] Add puppeteer config file --- tests/e2e/puppeteer.config.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/e2e/puppeteer.config.js diff --git a/tests/e2e/puppeteer.config.js b/tests/e2e/puppeteer.config.js new file mode 100644 index 00000000000..2e1ac374f0f --- /dev/null +++ b/tests/e2e/puppeteer.config.js @@ -0,0 +1,17 @@ +/** + * External dependencies + */ +const { executablePath } = require('puppeteer'); + +module.exports = { + launch: { + devtools: process.env.PUPPETEER_DEVTOOLS === 'true', + headless: process.env.PUPPETEER_HEADLESS !== 'false', + slowMo: parseInt(process.env.PUPPETEER_SLOWMO) || 0, + args: [ + '--enable-blink-features=ComputedAccessibilityInfo', + '--disable-web-security', + ], + executablePath: executablePath(), + }, +}; From 9a5cf5bf3e1c79c5ccb75143d761ece3b1509b95 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:01:14 +0530 Subject: [PATCH 3/8] Update menu creation in e2e tests --- tests/e2e/specs/core-themes/twentyfifteen.js | 8 ++---- tests/e2e/specs/core-themes/twentyfourteen.js | 8 ++---- tests/e2e/specs/core-themes/twentynineteen.js | 8 ++---- .../e2e/specs/core-themes/twentyseventeen.js | 8 ++---- tests/e2e/specs/core-themes/twentysixteen.js | 8 ++---- tests/e2e/specs/core-themes/twentythirteen.js | 8 ++---- tests/e2e/specs/core-themes/twentytwelve.js | 8 ++---- tests/e2e/specs/core-themes/twentytwenty.js | 8 ++---- .../e2e/specs/core-themes/twentytwentyone.js | 8 ++---- tests/e2e/utils/nav-menu-utils.js | 25 +++---------------- 10 files changed, 21 insertions(+), 76 deletions(-) diff --git a/tests/e2e/specs/core-themes/twentyfifteen.js b/tests/e2e/specs/core-themes/twentyfifteen.js index cd0dd6790bd..1480fa205fe 100644 --- a/tests/e2e/specs/core-themes/twentyfifteen.js +++ b/tests/e2e/specs/core-themes/twentyfifteen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Fifteen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentyfourteen.js b/tests/e2e/specs/core-themes/twentyfourteen.js index 395c15a6dbe..3da1f2d0855 100644 --- a/tests/e2e/specs/core-themes/twentyfourteen.js +++ b/tests/e2e/specs/core-themes/twentyfourteen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Fourteen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentynineteen.js b/tests/e2e/specs/core-themes/twentynineteen.js index 2052b002b6d..9f8f01ca3a9 100644 --- a/tests/e2e/specs/core-themes/twentynineteen.js +++ b/tests/e2e/specs/core-themes/twentynineteen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Nineteen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('menu-1'); + await createTestMenu('menu-1'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentyseventeen.js b/tests/e2e/specs/core-themes/twentyseventeen.js index b29743fd8c6..bef5e6d115f 100644 --- a/tests/e2e/specs/core-themes/twentyseventeen.js +++ b/tests/e2e/specs/core-themes/twentyseventeen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Seventeen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('top'); + await createTestMenu('top'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentysixteen.js b/tests/e2e/specs/core-themes/twentysixteen.js index 27b81981615..02d74d5d945 100644 --- a/tests/e2e/specs/core-themes/twentysixteen.js +++ b/tests/e2e/specs/core-themes/twentysixteen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Sixteen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentythirteen.js b/tests/e2e/specs/core-themes/twentythirteen.js index 5a9d0565a5f..767cc81f94c 100644 --- a/tests/e2e/specs/core-themes/twentythirteen.js +++ b/tests/e2e/specs/core-themes/twentythirteen.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Thirteen theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentytwelve.js b/tests/e2e/specs/core-themes/twentytwelve.js index f8327c3eef5..cef3b4f3f5d 100644 --- a/tests/e2e/specs/core-themes/twentytwelve.js +++ b/tests/e2e/specs/core-themes/twentytwelve.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Twelve theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/specs/core-themes/twentytwenty.js b/tests/e2e/specs/core-themes/twentytwenty.js index 4e51bad7480..4f1f4efd3a8 100644 --- a/tests/e2e/specs/core-themes/twentytwenty.js +++ b/tests/e2e/specs/core-themes/twentytwenty.js @@ -12,10 +12,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -42,8 +39,7 @@ describe('Twenty Twenty theme on AMP', () => { describe('main navigation', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('mobile'); + await createTestMenu('mobile'); }); it('should be initially hidden', async () => { diff --git a/tests/e2e/specs/core-themes/twentytwentyone.js b/tests/e2e/specs/core-themes/twentytwentyone.js index 68525bd38c5..ec3154ba3cc 100644 --- a/tests/e2e/specs/core-themes/twentytwentyone.js +++ b/tests/e2e/specs/core-themes/twentytwentyone.js @@ -13,10 +13,7 @@ import { * Internal dependencies */ import { setTemplateMode } from '../../utils/amp-settings-utils'; -import { - assignMenuToLocation, - createTestMenu, -} from '../../utils/nav-menu-utils'; +import { createTestMenu } from '../../utils/nav-menu-utils'; import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE, @@ -37,8 +34,7 @@ describe('Twenty Twenty-One theme on AMP', () => { describe('main navigation on mobile', () => { beforeAll(async () => { - await createTestMenu(); - await assignMenuToLocation('primary'); + await createTestMenu('primary'); }); beforeEach(async () => { diff --git a/tests/e2e/utils/nav-menu-utils.js b/tests/e2e/utils/nav-menu-utils.js index e2b6d5d74fe..d5aeffc07dd 100644 --- a/tests/e2e/utils/nav-menu-utils.js +++ b/tests/e2e/utils/nav-menu-utils.js @@ -1,17 +1,14 @@ /** * WordPress dependencies */ -import { - createMenu, - deleteAllMenus, - visitAdminPage, -} from '@wordpress/e2e-test-utils'; +import { createMenu, deleteAllMenus } from '@wordpress/e2e-test-utils'; -export async function createTestMenu() { +export async function createTestMenu(menuLocation = 'top') { await deleteAllMenus(); await createMenu( { name: 'Test Menu 1', + locations: [menuLocation], }, [ { @@ -33,19 +30,3 @@ export async function createTestMenu() { ] ); } - -export async function assignMenuToLocation(menuLocationName) { - await visitAdminPage('nav-menus.php', ''); - - // Bail out if there is no menu location or it is already selected. - const menuLocationCheckbox = await page.$( - `input:not(:checked)[name="menu-locations[${menuLocationName}]"]` - ); - if (!menuLocationCheckbox) { - return; - } - - await menuLocationCheckbox.click(); - await page.click('#save_menu_footer'); - await page.waitForSelector('#message', { text: /has been updated/ }); -} From b1d5b468fe6932d9ef6fc20bb6cf1a5b216b7ffc Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:04:41 +0530 Subject: [PATCH 4/8] Add puppeteer config file path --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f4399d0ab5a..47f2cf76b9d 100644 --- a/package.json +++ b/package.json @@ -135,12 +135,11 @@ "prepare": "husky install", "start": "wp-scripts start", "test": "npm-run-all --parallel test:*", - "test:e2e": "wp-scripts test-e2e --config=tests/e2e/jest.config.js", + "test:e2e": "cross-env JEST_PUPPETEER_CONFIG=./tests/e2e/puppeteer.config.js wp-scripts test-e2e --config=tests/e2e/jest.config.js", "test:e2e:help": "npm run test:e2e -- --help", "test:e2e:watch": "npm run test:e2e -- --watch", "test:e2e:interactive": "npm run test:e2e -- --puppeteer-interactive", - "pretest:e2e:ci": "npx patch-package", - "test:e2e:ci": "cross-env WP_BASE_URL=http://127.0.0.1:8890 wp-scripts test-e2e --config=tests/e2e/jest-ci.config.js --runInBand", + "test:e2e:ci": "cross-env WP_BASE_URL=http://127.0.0.1:8890 JEST_PUPPETEER_CONFIG=./tests/e2e/puppeteer.config.js wp-scripts test-e2e --config=tests/e2e/jest-ci.config.js --runInBand", "test:js": "wp-scripts test-unit-js --config=tests/js/jest.config.js", "test:js:help": "wp-scripts test-unit-js --help", "test:js:update-snapshots": "npm run test:js -- --updateSnapshot", From 12fb0aafe60ad6142cd0d0712116b76ab48438ca Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:17:37 +0530 Subject: [PATCH 5/8] Add chromium executable path in logs --- tests/e2e/puppeteer.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/e2e/puppeteer.config.js b/tests/e2e/puppeteer.config.js index 2e1ac374f0f..c03291c6f1e 100644 --- a/tests/e2e/puppeteer.config.js +++ b/tests/e2e/puppeteer.config.js @@ -3,6 +3,9 @@ */ const { executablePath } = require('puppeteer'); +// eslint-disable-next-line no-console, jest/require-hook +console.log(`Using Chromium from ${executablePath()}`); + module.exports = { launch: { devtools: process.env.PUPPETEER_DEVTOOLS === 'true', From 32c2c6414ff26b9baa3e1db7cf36639d8052f86e Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:29:19 +0530 Subject: [PATCH 6/8] Add puppeteer config file path in workflow env --- .github/workflows/build-test-measure.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index cfef1ab94d5..08a150ed9dd 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -198,6 +198,7 @@ jobs: actions: write env: WP_BASE_URL: 'http://127.0.0.1:8890' + JEST_PUPPETEER_CONFIG: './tests/e2e/puppeteer.config.js' strategy: fail-fast: false matrix: From 36246a69e0972662cff87b0c07efd690724879cc Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 02:54:56 +0530 Subject: [PATCH 7/8] Add step to cache puppeteer cache --- .github/workflows/build-test-measure.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index 08a150ed9dd..252014cb9ee 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -223,6 +223,12 @@ jobs: path: ~/.jest-cache key: ${{ runner.os }}-jest-e2e-${{ matrix.part }} + - name: Setup puppeteer cache + uses: actions/cache@v3.3.2 + with: + path: ~/.cache/puppeteer + key: ${{ runner.os }}-puppeteer + - name: Start Docker environment run: npm run env:start:ci env: From ee18f0a14f4fa611b78fa3fc915226b9eabf28ec Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 3 Nov 2023 17:08:20 +0530 Subject: [PATCH 8/8] Add default puppeteer config from wp-scripts config to puppeteer config --- tests/e2e/puppeteer.config.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/e2e/puppeteer.config.js b/tests/e2e/puppeteer.config.js index c03291c6f1e..aa03aeb5492 100644 --- a/tests/e2e/puppeteer.config.js +++ b/tests/e2e/puppeteer.config.js @@ -3,18 +3,21 @@ */ const { executablePath } = require('puppeteer'); +/** + * WordPress dependencies + */ +const defaultPuppeteerConfig = require('@wordpress/scripts/config/puppeteer.config.js'); + // eslint-disable-next-line no-console, jest/require-hook -console.log(`Using Chromium from ${executablePath()}`); +console.log( + `${ + process.env.CI ? '::notice::' : '' + }Using Chromium from ${executablePath()}` +); module.exports = { launch: { - devtools: process.env.PUPPETEER_DEVTOOLS === 'true', - headless: process.env.PUPPETEER_HEADLESS !== 'false', - slowMo: parseInt(process.env.PUPPETEER_SLOWMO) || 0, - args: [ - '--enable-blink-features=ComputedAccessibilityInfo', - '--disable-web-security', - ], + ...defaultPuppeteerConfig.launch, executablePath: executablePath(), }, };