[ci-jobs] Add disableHpos test environment variable (#47619)

* Add disableHpos test env variable

* Update events for HPOS disabled tests

* Add pull_request event to test the env

* Remove the pull_request event

* Add changelog

* Make the disableHpos var a boolean

* Also set the env in ci.yml

* Remove console log statement

* Print woocommerce_custom_orders_table_enabled

* Run test setup script again to check output

* Capture env setup output and print it

* Get woocommerce_custom_orders_table_enabled value in test env script

* Get more details on HPOS setting

* Remove the DISABLE_HPOS logic from test env setup script

* Use DISABLE_HPOS instead of ENABLE_HPOS everywhere

* Turn off no-console and jest/no-standalone-expect eslint rules for api core tests

* Test API tests with HPOS disabled

* Fix eslint error

* Clean up debug statements

* Remove pull_request test trigger
This commit is contained in:
Adrian Moldovan 2024-05-22 00:33:43 +03:00 committed by GitHub
parent ccba59ce05
commit cf6e01d0d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 57 additions and 38 deletions

View File

@ -101,6 +101,7 @@ jobs:
runs-on: 'ubuntu-20.04'
needs: 'project-jobs'
if: ${{ needs.project-jobs.outputs.e2e-test-jobs != '[]' }}
env: ${{ matrix.testEnv.envVars }}
strategy:
fail-fast: false
matrix:
@ -157,6 +158,7 @@ jobs:
runs-on: 'ubuntu-20.04'
needs: 'project-jobs'
if: ${{ needs.project-jobs.outputs.api-test-jobs != '[]' }}
env: ${{ matrix.testEnv.envVars }}
strategy:
fail-fast: false
matrix:

View File

@ -38,8 +38,6 @@ jobs:
- name: Load docker images and start containers.
working-directory: plugins/woocommerce
env:
ENABLE_HPOS: 1
run: pnpm --filter=@woocommerce/plugin-woocommerce env:test
- name: Run API tests

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Add new disableHpos test env variable in ci-job utility

View File

@ -29,7 +29,6 @@
"env:start": "pnpm wp-env start",
"env:stop": "pnpm wp-env stop",
"env:test": "pnpm env:dev && pnpm playwright install chromium",
"env:test:no-hpos": "DISABLE_HPOS=1 pnpm env:test",
"env:perf:install-k6": "curl https://github.com/grafana/k6/releases/download/v0.33.0/k6-v0.33.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1",
"env:perf": "pnpm env:dev && pnpm env:performance-init && pnpm env:perf:install-k6",
"preinstall": "npx only-allow pnpm",
@ -254,7 +253,10 @@
"tests/e2e-pw/**"
],
"testEnv": {
"start": "env:test:no-hpos"
"start": "env:test",
"config": {
"disableHpos": true
}
}
},
{
@ -297,7 +299,10 @@
"push"
],
"testEnv": {
"start": "env:test:no-hpos"
"start": "env:test",
"config": {
"disableHpos": true
}
}
},
{

View File

@ -3,9 +3,11 @@ module.exports = {
rules: {
'jsdoc/check-tag-names': 'off',
'jest/no-test-callback': 'off',
'camelcase': 'off',
camelcase: 'off',
'jest/no-disabled-tests': 'off',
'no-shadow': 'off',
'jest/no-identical-title': 'off',
'jest/no-standalone-expect': 'off',
'no-console': 'off',
},
};

View File

@ -1,4 +1,4 @@
const { ENABLE_HPOS, GITHUB_TOKEN, UPDATE_WC } = process.env;
const { DISABLE_HPOS, GITHUB_TOKEN, UPDATE_WC } = process.env;
const { downloadZip, deleteZip } = require( './utils/plugin-utils' );
const axios = require( 'axios' ).default;
const playwrightConfig = require( './playwright.config' );
@ -210,10 +210,10 @@ module.exports = async ( config ) => {
console.log( 'No DB update needed' );
}
} else {
// running on localhost using wp-env so ensure HPOS is set if ENABLE_HPOS env variable is passed
if ( ENABLE_HPOS ) {
// running on localhost using wp-env so ensure HPOS is set if DISABLE_HPOS env variable is passed
if ( DISABLE_HPOS ) {
let hposConfigured = false;
const value = ENABLE_HPOS === '0' ? 'no' : 'yes';
const value = DISABLE_HPOS === '1' ? 'no' : 'yes';
try {
const auth = {
username: playwrightConfig.userKey,
@ -240,7 +240,7 @@ module.exports = async ( config ) => {
}
if ( ! hposConfigured ) {
console.error(
'Cannot proceed to api tests, HPOS configuration failed. Please check if the correct ENABLE_HPOS value was used and the test site has been setup correctly.'
'Cannot proceed to api tests, HPOS configuration failed. Please check if the correct DISABLE_HPOS value was used and the test site has been setup correctly.'
);
process.exit( 1 );
}

View File

@ -1,15 +1,5 @@
#!/usr/bin/env bash
DISABLE_HPOS="${DISABLE_HPOS:-0}"
echo -e "DISABLE_HPOS: $DISABLE_HPOS"
if [ $DISABLE_HPOS == 1 ]; then
echo -e 'Disabling HPOS\n'
wp-env run tests-cli wp option update woocommerce_custom_orders_table_enabled 'no'
fi
ENABLE_TRACKING="${ENABLE_TRACKING:-0}"
echo -e 'Activate default theme \n'
wp-env run tests-cli wp theme activate twentytwentythree
@ -41,6 +31,8 @@ wp-env run tests-cli wp option update blogname 'WooCommerce Core E2E Test Suite'
echo -e 'Preparing Test Files \n'
wp-env run tests-cli sudo cp /var/www/html/wp-content/plugins/woocommerce/tests/legacy/unit-tests/importer/sample.csv /var/www/sample.csv
ENABLE_TRACKING="${ENABLE_TRACKING:-0}"
if [ $ENABLE_TRACKING == 1 ]; then
echo -e 'Enable tracking\n'
wp-env run tests-cli wp option update woocommerce_allow_tracking 'yes'

View File

@ -3,7 +3,7 @@ const { admin, customer } = require( './test-data/data' );
const fs = require( 'fs' );
const { site } = require( './utils' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const { ENABLE_HPOS } = process.env;
const { DISABLE_HPOS } = process.env;
/**
* @param {import('@playwright/test').FullConfig} config
@ -185,11 +185,11 @@ module.exports = async ( config ) => {
process.exit( 1 );
}
// While we're here, let's set HPOS according to the passed in ENABLE_HPOS env variable
// (if a value for ENABLE_HPOS was set)
// While we're here, let's set HPOS according to the passed in DISABLE_HPOS env variable
// (if a value for DISABLE_HPOS was set)
// This was always being set to 'yes' after login in wp-env so this step ensures the
// correct value is set before we begin our tests
console.log( `ENABLE_HPOS: ${ ENABLE_HPOS }` );
console.log( `DISABLE_HPOS: ${ DISABLE_HPOS }` );
const api = new wcApi( {
url: baseURL,
@ -198,10 +198,10 @@ module.exports = async ( config ) => {
version: 'wc/v3',
} );
if ( ENABLE_HPOS ) {
if ( DISABLE_HPOS ) {
const hposSettingRetries = 5;
const value = ENABLE_HPOS === '0' ? 'no' : 'yes';
const value = DISABLE_HPOS === '1' ? 'no' : 'yes';
for ( let i = 0; i < hposSettingRetries; i++ ) {
try {
@ -233,7 +233,7 @@ module.exports = async ( config ) => {
if ( ! hposConfigured ) {
console.error(
'Cannot proceed e2e test, HPOS configuration failed. Please check if the correct ENABLE_HPOS value was used and the test site has been setup correctly.'
'Cannot proceed e2e test, HPOS configuration failed. Please check if the correct DISABLE_HPOS value was used and the test site has been setup correctly.'
);
process.exit( 1 );
}
@ -242,8 +242,11 @@ module.exports = async ( config ) => {
const response = await api.get(
'settings/advanced/woocommerce_custom_orders_table_enabled'
);
console.log( `HPOS configuration ${ response.data.value }` );
const dataValue = response.data.value;
const enabledOption = response.data.options[ dataValue ];
console.log(
`HPOS configuration (woocommerce_custom_orders_table_enabled): ${ dataValue } - ${ enabledOption }`
);
await site.useCartCheckoutShortcodes( baseURL, userAgent, admin );

View File

@ -1,7 +1,5 @@
#!/bin/bash
ENABLE_HPOS="${ENABLE_HPOS:-0}"
echo "Initializing WooCommerce E2E"
wp-env run tests-cli wp plugin activate woocommerce
@ -33,9 +31,4 @@ wp-env run tests-cli wp import wp-content/plugins/woocommerce/sample-data/sample
# install Storefront
wp-env run tests-cli wp theme install storefront --activate
if [ $ENABLE_HPOS == 1 ]; then
echo -e 'Enable High-Performance Order Tables\n'
wp-env run tests-cli wp plugin install https://gist.github.com/vedanshujain/564afec8f5e9235a1257994ed39b1449/archive/b031465052fc3e04b17624acbeeb2569ef4d5301.zip --activate
fi
echo "Success! Your E2E Test Environment is now ready."

File diff suppressed because one or more lines are too long

View File

@ -233,6 +233,11 @@ export interface TestEnvConfigVars {
* The version of PHP that should be used.
*/
phpVersion?: string;
/**
* Whether the HPOS feature should be disabled in the test environment setup.
*/
disableHpos?: boolean;
}
/**
@ -264,6 +269,16 @@ function parseTestEnvConfigVars( raw: any ): TestEnvConfigVars {
config.phpVersion = raw.phpVersion;
}
if ( raw.disableHpos ) {
if ( typeof raw.disableHpos !== 'boolean' ) {
throw new ConfigError(
'The "disableHpos" option must be a boolean.'
);
}
config.disableHpos = raw.disableHpos;
}
return config;
}

View File

@ -169,6 +169,7 @@ async function parseWPVersion( wpVersion: string ): Promise< string > {
export interface TestEnvVars {
WP_ENV_CORE?: string;
WP_ENV_PHP_VERSION?: string;
DISABLE_HPOS?: number;
}
/**
@ -197,5 +198,9 @@ export async function parseTestEnvConfig(
envVars.WP_ENV_PHP_VERSION = config.phpVersion;
}
if ( config.disableHpos ) {
envVars.DISABLE_HPOS = 1;
}
return envVars;
}