Merge branch 'woocommerce:trunk' into fix/45103

This commit is contained in:
PavloBorysenko 2024-10-09 15:53:53 +02:00 committed by GitHub
commit b32bcbb173
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 99 additions and 50 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: fix the global teardown failing with wp6.7-beta1

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Updates to core e2e tests for WP 6.7 compatibility

View File

@ -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&section=keys`
);
@ -92,6 +85,7 @@ module.exports = async ( config ) => {
break;
} catch ( e ) {
console.log( 'Failed to clear consumer token. Retrying...' );
console.log( e );
}
}

View File

@ -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

View File

@ -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();

View File

@ -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( {} );
} );
} );
} );
} );