From d7e4caab69e6c27e8acab16c3e97d6a6ce546163 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:13:49 +0100 Subject: [PATCH 01/12] Feat: Output faust version in dev|build|start commands. --- .changeset/shaggy-carpets-bow.md | 15 +++++++ packages/faustwp-cli/src/index.ts | 3 ++ .../src/telemetry/marshallTelemetryData.ts | 29 +------------ packages/faustwp-cli/src/utils/index.ts | 1 + .../src/utils/printFaustVersion.ts | 42 +++++++++++++++++++ 5 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 .changeset/shaggy-carpets-bow.md create mode 100644 packages/faustwp-cli/src/utils/printFaustVersion.ts diff --git a/.changeset/shaggy-carpets-bow.md b/.changeset/shaggy-carpets-bow.md new file mode 100644 index 000000000..7e497b0dd --- /dev/null +++ b/.changeset/shaggy-carpets-bow.md @@ -0,0 +1,15 @@ +--- +'@faustwp/cli': patch +--- + +Faust CLI now outputs version number when running dev|build|start commands. + +When running those commands it will print the current Faust core and cli versions in the console: + +```bash +% npm run dev -w examples/next/faustwp-getting-started +info - Faust.js v3.0.1 +info - Faust.js CLI v3.0.1 +ready - started server on 0.0.0.0:3000, url: http://localhost:3000 +... +``` diff --git a/packages/faustwp-cli/src/index.ts b/packages/faustwp-cli/src/index.ts index a55241ed2..2a94da992 100644 --- a/packages/faustwp-cli/src/index.ts +++ b/packages/faustwp-cli/src/index.ts @@ -11,6 +11,7 @@ import { getNextCliArgs, getWpSecret, isDebug, + printFaustVersion, } from './utils/index.js'; import { marshallTelemetryData, sendTelemetryData } from './telemetry/index.js'; @@ -81,6 +82,8 @@ import { marshallTelemetryData, sendTelemetryData } from './telemetry/index.js'; } } + printFaustVersion(); + /** * Spawn a child process using the args captured in argv and continue the * standard i/o for the Next.js CLI. diff --git a/packages/faustwp-cli/src/telemetry/marshallTelemetryData.ts b/packages/faustwp-cli/src/telemetry/marshallTelemetryData.ts index 86ca6b489..07b6a1f5a 100644 --- a/packages/faustwp-cli/src/telemetry/marshallTelemetryData.ts +++ b/packages/faustwp-cli/src/telemetry/marshallTelemetryData.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import { getCliArgs } from '../utils/index.js'; +import { sanitizePackageJsonVersion } from '../utils/printFaustVersion.js'; export interface TelemetryData { node_faustwp_core_version?: string; @@ -14,34 +15,6 @@ export interface TelemetryData { command?: string; } -/** - * Sanitizes the version from a dependency in package.json. - * - * @param version The dependency version. - * @returns A sanitized version or undefined if the version is a path. - */ -const sanitizePackageJsonVersion = (_version: string | undefined) => { - let version = _version; - - if (!version) { - return undefined; - } - - if (version.charAt(0) === '^' || version.charAt(0) === '~') { - version = version.substring(1); - } - - /** - * If a dependency is a file path set the value to undefined as we - * don't want to collect file paths in telemetry - */ - if (version.startsWith('file:')) { - version = undefined; - } - - return version; -}; - /** * Marshall the JS telemetry data. * @param command Command that initiated the request diff --git a/packages/faustwp-cli/src/utils/index.ts b/packages/faustwp-cli/src/utils/index.ts index 9aa4358c9..8398cffbe 100644 --- a/packages/faustwp-cli/src/utils/index.ts +++ b/packages/faustwp-cli/src/utils/index.ts @@ -5,3 +5,4 @@ export { getWpSecret } from './getWpSecret.js'; export { getWpUrl } from './getWpUrl.js'; export { getGraphqlEndpoint } from './getGraphqlEndpoint.js'; export { hasYarn } from './hasYarn.js'; +export { printFaustVersion } from './printFaustVersion.js'; diff --git a/packages/faustwp-cli/src/utils/printFaustVersion.ts b/packages/faustwp-cli/src/utils/printFaustVersion.ts new file mode 100644 index 000000000..c852fd49f --- /dev/null +++ b/packages/faustwp-cli/src/utils/printFaustVersion.ts @@ -0,0 +1,42 @@ +import fs from 'fs'; +import { infoLog } from '../stdout/index.js'; + +/** + * Sanitizes the version from a dependency in package.json. + * + * @param version The dependency version. + * @returns A sanitized version or undefined if the version is a path. + */ +export function sanitizePackageJsonVersion(_version: string | undefined) { + let version = _version; + + if (!version) { + return undefined; + } + + if (version.charAt(0) === '^' || version.charAt(0) === '~') { + version = version.substring(1); + } + + /** + * If a dependency is a file path set the value to undefined as we + * don't want to collect file paths in telemetry + */ + if (version.startsWith('file:')) { + version = undefined; + } + + return version; +} + +export function printFaustVersion(): void { + const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + const coreVersion = sanitizePackageJsonVersion( + packageJson?.dependencies?.['@faustwp/core'] as string | undefined, + ); + const cliVersion = sanitizePackageJsonVersion( + packageJson?.dependencies?.['@faustwp/cli'] as string | undefined, + ); + infoLog(`Faust.js v${coreVersion}`); + infoLog(`Faust.js CLI v${cliVersion}`); +} From 05cc37150cbd7814988a09e2c29066f596d823a3 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:35:44 +0100 Subject: [PATCH 02/12] Lint: Fix eslint issue --- packages/faustwp-cli/src/utils/printFaustVersion.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/faustwp-cli/src/utils/printFaustVersion.ts b/packages/faustwp-cli/src/utils/printFaustVersion.ts index c852fd49f..be8ca7f93 100644 --- a/packages/faustwp-cli/src/utils/printFaustVersion.ts +++ b/packages/faustwp-cli/src/utils/printFaustVersion.ts @@ -37,6 +37,7 @@ export function printFaustVersion(): void { const cliVersion = sanitizePackageJsonVersion( packageJson?.dependencies?.['@faustwp/cli'] as string | undefined, ); - infoLog(`Faust.js v${coreVersion}`); - infoLog(`Faust.js CLI v${cliVersion}`); + // eslint-disable-next-line + infoLog(`Faust.js v${coreVersion || 'unknown'}`); + infoLog(`Faust.js CLI v${cliVersion || 'unknown'}`); } From 8d97c660c1c3e1bc6f2286cce60c374cd9f06054 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:33:07 +0100 Subject: [PATCH 03/12] Acceptance Tests: update preview button selectos for WP 6.5 --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 2 +- plugins/faustwp/tests/acceptance/PostPreviewCest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index aedae6fa2..743dff96a 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -38,7 +38,7 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->amEditingPostWithId($cpt_id); $I->click('div.components-guide .components-modal__header button.components-button'); - $I->click('button.block-editor-post-preview__button-toggle'); + $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index 4419f51f4..cd2dc200e 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -23,7 +23,7 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->loginAsAdmin(); $I->amEditingPostWithId($post_id); - $I->click('button.block-editor-post-preview__button-toggle'); + $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', From 83fdb7b885071109044c27e952e67d85413ff1d7 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:14:49 +0100 Subject: [PATCH 04/12] Acceptance Tests: Attempt to fix preview tests --- .../faustwp/tests/acceptance/CustomPostTypeCest.php | 12 ++++++++---- plugins/faustwp/tests/acceptance/PostPreviewCest.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 743dff96a..4b4c416a6 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -36,13 +36,17 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); - $I->click('div.components-guide .components-modal__header button.components-button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( - 'Preview in new tab', - "${front_end_url}/document/${cpt_name}/?preview=true&previewPathname=" . rawurlencode("/document/cpt-document-preview/") . "&p=${cpt_id}&typeName=Document", - ); + 'Preview in new tab', + "${front_end_url}/${post_name}/?preview=true", + ); + + $I->click('Preview in new tab'); + $I->switchToNextTab(); + $I->wait(14); // Wait for authentication + $I->see($post_title, 'section h1'); } } diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index cd2dc200e..697e997a4 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -27,7 +27,7 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', - "${front_end_url}/${post_name}/?preview=true&previewPathname=" . rawurlencode("/post-preview-post/") . "&p=${post_id}&typeName=Post", + "${front_end_url}/${post_name}/?preview=true", ); $I->click('Preview in new tab'); From c555a8cd9fdc874e8b8effa019c0a8b3986c1589 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:15:42 +0100 Subject: [PATCH 05/12] Acceptance Test: Use correct variables --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 4b4c416a6..ae7d081a8 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -47,6 +47,7 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->click('Preview in new tab'); $I->switchToNextTab(); $I->wait(14); // Wait for authentication - $I->see($post_title, 'section h1'); + $I->see($cpt_title, 'section h1'); + $I->see($cpt_content, 'main.content-single .wrap p'); } } From ed1fa9febb85e67ccccccaa7c67bc3ca0350e626 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:26:52 +0100 Subject: [PATCH 06/12] Acceptance Test: Fix cpt_name var --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index ae7d081a8..e5332fa2b 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -41,7 +41,7 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', - "${front_end_url}/${post_name}/?preview=true", + "${front_end_url}/${cpt_name}/?preview=true", ); $I->click('Preview in new tab'); From ec31be347a00b6560993871e8ae64951aba09256 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:42:22 +0100 Subject: [PATCH 07/12] Acceptance Test: Remove click event --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index e5332fa2b..6edb4249b 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -36,7 +36,6 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); - $I->click('div.components-guide .components-modal__header button.components-button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( From 3be607ef50b6c1aa67731d67db2b5285d923898e Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:51:45 +0100 Subject: [PATCH 08/12] Acceptance Test: Attempt to close welcome modals. --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 4 ++-- plugins/faustwp/tests/acceptance/PostPreviewCest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 6edb4249b..48bdf99d2 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -36,13 +36,13 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); + $I->click('div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', - "${front_end_url}/${cpt_name}/?preview=true", + "${front_end_url}/document/${cpt_name}/?preview=true", ); - $I->click('Preview in new tab'); $I->switchToNextTab(); $I->wait(14); // Wait for authentication diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index 697e997a4..94ea65cee 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -23,6 +23,7 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->loginAsAdmin(); $I->amEditingPostWithId($post_id); + $I->click('div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( From df2d8688bb75fb510d14271b8a30c146af451481 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:04:26 +0100 Subject: [PATCH 09/12] Acceptance Test: Revert last commit --- plugins/faustwp/tests/acceptance/CustomPostTypeCest.php | 1 - plugins/faustwp/tests/acceptance/PostPreviewCest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 48bdf99d2..071d68d0b 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -36,7 +36,6 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); - $I->click('div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index 94ea65cee..697e997a4 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -23,7 +23,6 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->loginAsAdmin(); $I->amEditingPostWithId($post_id); - $I->click('div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( From 439e2e7d411392901d92ee4f2b872d4756badc6d Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:04:47 +0100 Subject: [PATCH 10/12] Acceptance Test: Update DEVELOPMENT.md --- DEVELOPMENT.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c23eb1aa1..b1660e88d 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -133,14 +133,15 @@ FAUST_SECRET_KEY=00000000-0000-4000-8000-000000000001 ### 3. WordPress Setup 1. Leave the node server running and open a new shell. -1. Move into the FaustWP plugin directory `plugins/faustwp`. -1. Run `composer install` if you haven't already. -1. Prepare a test WordPress site. +2. Move into the FaustWP plugin directory `plugins/faustwp`. +3. Run `composer install` if you haven't already. +4. Prepare a test WordPress site. 1. Run `docker-compose up -d --build`. If building for the first time, it could take some time to download and build the images. - 1. Run `docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root` - 1. Run `docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp db export tests/_data/dump.sql --allow-root` -1. Copy `.env.testing.example` to `.env.testing`. -1. Run `vendor/bin/codecept run acceptance` to start the end-2-end tests. + 2. Run `docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root` + 3. Run `docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp core update-db --allow-root ` + 4. Run `docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp db export tests/_data/dump.sql --allow-root` +5. Copy `.env.testing.example` to `.env.testing`. +6. Run `vendor/bin/codecept run acceptance` to start the end-2-end tests. ### Browser testing documentation @@ -207,21 +208,21 @@ Once deployed, the updated packages and plugin will be visible here: - https://www.npmjs.com/package/@faustwp/blocks - https://plugins.trac.wordpress.org/browser/faustwp/tags - ### Working with the Monorepo + This section offers guidance for developers working within the monorepo environment, which utilizes npm for package management. #### Navigation: -* Use your terminal or IDE to navigate the file structure. -* To locate a specific project, navigate to its directory within the packages folder. For example, `cd packages/faustwp-core` would take you to the `faustwp-core` project directory. +- Use your terminal or IDE to navigate the file structure. +- To locate a specific project, navigate to its directory within the packages folder. For example, `cd packages/faustwp-core` would take you to the `faustwp-core` project directory. #### Building and Deploying: -* We use npm for managing dependencies and running build scripts. -* Individual projects often have their own package.json file with project-specific scripts for building and deploying. You can run these scripts using commands like `npm run build` or `npm run test` within the project directory (e.g., `packages/faustwp-core`). -* Refer to the project's README file or internal documentation for specific build and deploy instructions. -For deploying the entire monorepo, there might be a top-level build script which you can invoke with `npm run build`. +- We use npm for managing dependencies and running build scripts. +- Individual projects often have their own package.json file with project-specific scripts for building and deploying. You can run these scripts using commands like `npm run build` or `npm run test` within the project directory (e.g., `packages/faustwp-core`). +- Refer to the project's README file or internal documentation for specific build and deploy instructions. + For deploying the entire monorepo, there might be a top-level build script which you can invoke with `npm run build`. #### Additional Considerations: @@ -230,5 +231,5 @@ Use the `--workspaces` or `-w` flag to run a specific script command of a specif ```bash $ npm run build -w examples/next/faustwp-getting-started ``` -It runs the `build` npm script for the `faustwp-getting-started` example project. +It runs the `build` npm script for the `faustwp-getting-started` example project. From dcb4d6d21c9f52c3ca40d5b3c642537ca1dd318f Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:19:14 +0100 Subject: [PATCH 11/12] Acceptance Test: Click Welcome modal if present --- .../faustwp/tests/acceptance/CustomPostTypeCest.php | 10 ++++++++++ plugins/faustwp/tests/acceptance/PostPreviewCest.php | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 071d68d0b..8b1b7908f 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -2,6 +2,14 @@ class CustomPostTypeCest { + private function _clickElementIfPresent($I, $element) + { + try { + $I->click($element); + } catch (\PHPUnit_Framework_ExpectationFailedException $e) { + } + return; + } public function _before(AcceptanceTester $I) { @@ -36,12 +44,14 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); + $this->_clickElementIfPresent($I, 'div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', "${front_end_url}/document/${cpt_name}/?preview=true", ); + $I->click('Preview in new tab'); $I->switchToNextTab(); $I->wait(14); // Wait for authentication diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index 697e997a4..3e0b1cb00 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -2,6 +2,14 @@ class PostPreviewCest { + private function _clickElementIfPresent($I, $element) + { + try { + $I->click($element); + } catch (\PHPUnit_Framework_ExpectationFailedException $e) { + } + return; + } /** * Ensure the nodejs site url is set as the post preview url. */ @@ -23,6 +31,7 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->loginAsAdmin(); $I->amEditingPostWithId($post_id); + $this->_clickElementIfPresent($I, 'div.components-modal__header > button'); $I->click('button.editor-preview-dropdown__toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( From 48cb974da419cb20287c345a8cae743ec861d5f5 Mon Sep 17 00:00:00 2001 From: Theo <328805+theodesp@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:46:58 +0100 Subject: [PATCH 12/12] Acceptance Test: Pin e2e tests to WP 6.4 --- plugins/faustwp/.docker/Dockerfile | 2 +- .../tests/acceptance/CustomPostTypeCest.php | 25 +++++-------------- .../tests/acceptance/PostPreviewCest.php | 13 ++-------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/plugins/faustwp/.docker/Dockerfile b/plugins/faustwp/.docker/Dockerfile index 4acb728d7..a702b8e79 100644 --- a/plugins/faustwp/.docker/Dockerfile +++ b/plugins/faustwp/.docker/Dockerfile @@ -1,4 +1,4 @@ -ARG WP_VERSION=latest +ARG WP_VERSION=6.4 FROM wordpress:${WP_VERSION} diff --git a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php index 8b1b7908f..aedae6fa2 100644 --- a/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php +++ b/plugins/faustwp/tests/acceptance/CustomPostTypeCest.php @@ -2,14 +2,6 @@ class CustomPostTypeCest { - private function _clickElementIfPresent($I, $element) - { - try { - $I->click($element); - } catch (\PHPUnit_Framework_ExpectationFailedException $e) { - } - return; - } public function _before(AcceptanceTester $I) { @@ -44,18 +36,13 @@ public function i_can_view_the_custom_post_type_preview_link(AcceptanceTester $I $I->loginAsAdmin(); $I->amEditingPostWithId($cpt_id); - $this->_clickElementIfPresent($I, 'div.components-modal__header > button'); - $I->click('button.editor-preview-dropdown__toggle'); + + $I->click('div.components-guide .components-modal__header button.components-button'); + $I->click('button.block-editor-post-preview__button-toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( - 'Preview in new tab', - "${front_end_url}/document/${cpt_name}/?preview=true", - ); - - $I->click('Preview in new tab'); - $I->switchToNextTab(); - $I->wait(14); // Wait for authentication - $I->see($cpt_title, 'section h1'); - $I->see($cpt_content, 'main.content-single .wrap p'); + 'Preview in new tab', + "${front_end_url}/document/${cpt_name}/?preview=true&previewPathname=" . rawurlencode("/document/cpt-document-preview/") . "&p=${cpt_id}&typeName=Document", + ); } } diff --git a/plugins/faustwp/tests/acceptance/PostPreviewCest.php b/plugins/faustwp/tests/acceptance/PostPreviewCest.php index 3e0b1cb00..4419f51f4 100644 --- a/plugins/faustwp/tests/acceptance/PostPreviewCest.php +++ b/plugins/faustwp/tests/acceptance/PostPreviewCest.php @@ -2,14 +2,6 @@ class PostPreviewCest { - private function _clickElementIfPresent($I, $element) - { - try { - $I->click($element); - } catch (\PHPUnit_Framework_ExpectationFailedException $e) { - } - return; - } /** * Ensure the nodejs site url is set as the post preview url. */ @@ -31,12 +23,11 @@ public function i_can_view_the_post_preview_link(AcceptanceTester $I) $I->loginAsAdmin(); $I->amEditingPostWithId($post_id); - $this->_clickElementIfPresent($I, 'div.components-modal__header > button'); - $I->click('button.editor-preview-dropdown__toggle'); + $I->click('button.block-editor-post-preview__button-toggle'); $I->wait(4); // Wait for previewlinks.js to modify button href. $I->seeLink( 'Preview in new tab', - "${front_end_url}/${post_name}/?preview=true", + "${front_end_url}/${post_name}/?preview=true&previewPathname=" . rawurlencode("/post-preview-post/") . "&p=${post_id}&typeName=Post", ); $I->click('Preview in new tab');