From cb77b906224ae6d46f456096c1fc530009a663d7 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:21:26 -0500 Subject: [PATCH 1/3] [e2e tests] Fix broken gloabal-teardown with WP 6.7-beta1 (#51958) --- .../changelog/e2e-fix-global-teardown-wp6.7.beta1 | 4 ++++ plugins/woocommerce/tests/e2e-pw/global-teardown.js | 12 +++--------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 plugins/woocommerce/changelog/e2e-fix-global-teardown-wp6.7.beta1 diff --git a/plugins/woocommerce/changelog/e2e-fix-global-teardown-wp6.7.beta1 b/plugins/woocommerce/changelog/e2e-fix-global-teardown-wp6.7.beta1 new file mode 100644 index 00000000000..443c4eef02e --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-fix-global-teardown-wp6.7.beta1 @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +E2E tests: fix the global teardown failing with wp6.7-beta1 diff --git a/plugins/woocommerce/tests/e2e-pw/global-teardown.js b/plugins/woocommerce/tests/e2e-pw/global-teardown.js index 5e18f22e493..0b8ebb2a4fa 100644 --- a/plugins/woocommerce/tests/e2e-pw/global-teardown.js +++ b/plugins/woocommerce/tests/e2e-pw/global-teardown.js @@ -1,5 +1,6 @@ const { chromium, expect } = require( '@playwright/test' ); const { admin } = require( './test-data/data' ); +const { logIn } = require( './utils/login' ); module.exports = async ( config ) => { const { baseURL, userAgent } = config.projects[ 0 ].use; @@ -20,15 +21,7 @@ module.exports = async ( config ) => { try { console.log( 'Trying to clear consumer token... Try:' + i ); await adminPage.goto( `/wp-admin` ); - await adminPage - .locator( 'input[name="log"]' ) - .fill( admin.username ); - await adminPage - .locator( 'input[name="pwd"]' ) - .fill( admin.password ); - await adminPage.locator( 'text=Log In' ).click(); - // eslint-disable-next-line playwright/no-networkidle - await adminPage.waitForLoadState( 'networkidle' ); + await logIn( adminPage, admin.username, admin.password ); await adminPage.goto( `/wp-admin/admin.php?page=wc-settings&tab=advanced§ion=keys` ); @@ -92,6 +85,7 @@ module.exports = async ( config ) => { break; } catch ( e ) { console.log( 'Failed to clear consumer token. Retrying...' ); + console.log( e ); } } From a35e55081fadc2d22922233ca4a150cade39e2a7 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:49:31 -0500 Subject: [PATCH 2/3] [ci-jobs] Add new unit tests to validate the prerelease WP offer flow in jobs matrix (#51880) --- .../lib/__tests__/test-environment.spec.ts | 98 +++++++++++++++---- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/tools/monorepo-utils/src/ci-jobs/lib/__tests__/test-environment.spec.ts b/tools/monorepo-utils/src/ci-jobs/lib/__tests__/test-environment.spec.ts index ebdb1dd88d5..1ad49531dd6 100644 --- a/tools/monorepo-utils/src/ci-jobs/lib/__tests__/test-environment.spec.ts +++ b/tools/monorepo-utils/src/ci-jobs/lib/__tests__/test-environment.spec.ts @@ -11,6 +11,31 @@ import { parseTestEnvConfig } from '../test-environment'; jest.mock( 'node:http' ); +function mockWordPressAPI( + stableCheckResponse: any, + versionCheckResponse: any +) { + jest.mocked( get ).mockImplementation( ( url, callback: any ) => { + const getStream = new Stream(); + callback( getStream as IncomingMessage ); + + if ( url === 'http://api.wordpress.org/core/stable-check/1.0/' ) { + getStream.emit( 'data', JSON.stringify( stableCheckResponse ) ); + } else if ( + url + .toString() + .includes( 'http://api.wordpress.org/core/version-check/1.7' ) + ) { + getStream.emit( 'data', JSON.stringify( versionCheckResponse ) ); + } else { + throw new Error( 'Invalid URL' ); + } + + getStream.emit( 'end' ); + return jest.fn() as any; + } ); +} + describe( 'Test Environment', () => { describe( 'parseTestEnvConfig', () => { it( 'should parse empty configs', async () => { @@ -22,19 +47,8 @@ describe( 'Test Environment', () => { describe( 'wpVersion', () => { // We're going to mock an implementation of the request to the WordPress.org API. // This simulates what happens when we call https.get() for it. - jest.mocked( get ).mockImplementation( ( url, callback: any ) => { - if ( - url !== 'http://api.wordpress.org/core/stable-check/1.0/' - ) { - throw new Error( 'Invalid URL' ); - } - - const getStream = new Stream(); - - // Let the consumer set up listeners for the stream. - callback( getStream as IncomingMessage ); - - const wpVersions = { + mockWordPressAPI( + { '5.9': 'insecure', '6.0': 'insecure', '6.0.1': 'insecure', @@ -42,14 +56,18 @@ describe( 'Test Environment', () => { '6.1.1': 'insecure', '6.1.2': 'outdated', '6.2': 'latest', - }; - - getStream.emit( 'data', JSON.stringify( wpVersions ) ); - - getStream.emit( 'end' ); // this will trigger the promise resolve - - return jest.fn() as any; - } ); + }, + { + offers: [ + { + response: 'development', + version: '6.3-beta1', + download: + 'https://wordpress.org/wordpress-6.3-beta1.zip', + }, + ], + } + ); it( 'should parse "master" and "trunk" branches', async () => { let envVars = await parseTestEnvConfig( { @@ -148,6 +166,44 @@ describe( 'Test Environment', () => { /Failed to parse WP version/ ); } ); + + it( 'should parse the prerelease offer', async () => { + const envVars = await parseTestEnvConfig( { + wpVersion: 'prerelease', + } ); + + expect( envVars ).toEqual( { + WP_ENV_CORE: + 'https://wordpress.org/wordpress-6.3-beta1.zip', + WP_VERSION: '6.3-beta1', + } ); + } ); + + it( 'should not create env vars if no prerelease is offered', async () => { + mockWordPressAPI( + { + '6.1.1': 'insecure', + '6.1.2': 'outdated', + '6.2': 'latest', + }, + { + offers: [ + { + response: 'latest', + version: '6.2', + download: + 'https://wordpress.org/wordpress-6.2.zip', + }, + ], + } + ); + + const envVars = await parseTestEnvConfig( { + wpVersion: 'prerelease', + } ); + + expect( envVars ).toEqual( {} ); + } ); } ); } ); } ); From 5110f7138288ae524fa760468daf8bfb7110a3a2 Mon Sep 17 00:00:00 2001 From: Jonathan Lane Date: Tue, 8 Oct 2024 23:17:47 -0500 Subject: [PATCH 3/3] Update block checkout tests and product creation tests for WP 6.7 compatibility (#51965) Co-authored-by: Jon Lane --- .../e2e-test-updates-for-wp67-compatibility | 4 ++++ .../merchant/product-create-simple.spec.js | 7 +----- .../tests/shopper/checkout-block.spec.js | 24 ++++++++----------- 3 files changed, 15 insertions(+), 20 deletions(-) create mode 100644 plugins/woocommerce/changelog/e2e-test-updates-for-wp67-compatibility diff --git a/plugins/woocommerce/changelog/e2e-test-updates-for-wp67-compatibility b/plugins/woocommerce/changelog/e2e-test-updates-for-wp67-compatibility new file mode 100644 index 00000000000..fd56481e58d --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-test-updates-for-wp67-compatibility @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Updates to core e2e tests for WP 6.7 compatibility diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/product-create-simple.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/product-create-simple.spec.js index 2cd22b196a0..cce7887d24f 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/product-create-simple.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/product-create-simple.spec.js @@ -145,12 +145,7 @@ for ( const productType of Object.keys( productData ) ) { } ); await test.step( 'add product categories', async () => { - // Using getByRole here is unreliable - const categoryCheckbox = page.locator( - `#in-product_cat-${ category.id }` - ); - await categoryCheckbox.check(); - await expect( categoryCheckbox ).toBeChecked(); + await page.getByText( category.name ).first().check(); await expect( page diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js index 8de71c73567..ced090e4a7b 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js @@ -9,6 +9,7 @@ const { test: baseTest, expect } = require( '../../fixtures/fixtures' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const { admin, customer } = require( '../../test-data/data' ); +const { logIn } = require( '../../utils/login' ); const { setFilterValue, clearFilters } = require( '../../utils/filters' ); const { @@ -721,9 +722,7 @@ test.describe( ).toBeVisible(); await page.goto( 'wp-login.php' ); - await page.locator( 'input[name="log"]' ).fill( admin.username ); - await page.locator( 'input[name="pwd"]' ).fill( admin.password ); - await page.locator( 'text=Log In' ).click(); + await logIn( page, admin.username, admin.password, false ); // load the order placed as a guest await page.goto( @@ -820,9 +819,7 @@ test.describe( // Switch to admin user. await page.goto( 'wp-login.php?loggedout=true' ); - await page.locator( 'input[name="log"]' ).fill( admin.username ); - await page.locator( 'input[name="pwd"]' ).fill( admin.password ); - await page.locator( 'text=Log In' ).click(); + await logIn( page, admin.username, admin.password, false ); // load the order placed as a customer await page.goto( @@ -913,9 +910,7 @@ test.describe( // sign in as admin to confirm account creation await page.goto( 'wp-admin/users.php' ); - await page.locator( 'input[name="log"]' ).fill( admin.username ); - await page.locator( 'input[name="pwd"]' ).fill( admin.password ); - await page.locator( 'text=Log in' ).click(); + await logIn( page, admin.username, admin.password, false ); await expect( page.locator( 'tbody#the-list' ) ).toContainText( newAccountEmail ); @@ -1014,11 +1009,12 @@ test.describe( // Log in again. await page.goto( '/my-account/' ); - await page - .locator( '#username' ) - .fill( newAccountEmailWithCustomPassword ); - await page.locator( '#password' ).fill( newAccountCustomPassword ); - await page.locator( 'text=Log in' ).click(); + await logIn( + page, + newAccountEmailWithCustomPassword, + newAccountCustomPassword, + false + ); await expect( page.getByRole( 'heading', { name: 'My account' } ) ).toBeVisible();