From 61d41adf7957b269fec3f4931116476db4fe2671 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:53:00 +0100 Subject: [PATCH] [k6 tests] Fix broken perf tests - updated page titles (#51173) --- .../k6-fix-broken-tests-update-page-titles | 4 + .../woocommerce/tests/performance/config.js | 3 + .../woocommerce/tests/performance/headers.js | 101 +++---- .../requests/merchant/add-order.js | 262 ++++++++++++------ .../requests/merchant/home-wc-admin.js | 7 +- .../requests/shopper/cart-apply-coupon.js | 25 +- .../requests/shopper/cart-remove-item.js | 18 +- .../performance/requests/shopper/cart.js | 30 +- .../requests/shopper/category-page.js | 27 +- .../shopper/checkout-customer-login.js | 73 ++--- .../requests/shopper/checkout-guest.js | 66 ++--- .../performance/requests/shopper/home.js | 23 +- .../requests/shopper/my-account-orders.js | 81 ++---- .../requests/shopper/my-account.js | 30 +- .../requests/shopper/search-product.js | 26 +- .../performance/requests/shopper/shop-page.js | 32 +-- .../requests/shopper/single-product.js | 26 +- .../woocommerce/tests/performance/utils.js | 30 ++ 18 files changed, 435 insertions(+), 429 deletions(-) create mode 100644 plugins/woocommerce/changelog/k6-fix-broken-tests-update-page-titles create mode 100644 plugins/woocommerce/tests/performance/utils.js diff --git a/plugins/woocommerce/changelog/k6-fix-broken-tests-update-page-titles b/plugins/woocommerce/changelog/k6-fix-broken-tests-update-page-titles new file mode 100644 index 00000000000..4f73f5cc6c2 --- /dev/null +++ b/plugins/woocommerce/changelog/k6-fix-broken-tests-update-page-titles @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + + diff --git a/plugins/woocommerce/tests/performance/config.js b/plugins/woocommerce/tests/performance/config.js index 30dd0d2c4a7..d4638940de0 100644 --- a/plugins/woocommerce/tests/performance/config.js +++ b/plugins/woocommerce/tests/performance/config.js @@ -2,6 +2,9 @@ export const base_url = __ENV.URL || 'http://localhost:8086'; export const base_host = __ENV.HOST || 'localhost:8086'; +export const STORE_NAME = __ENV.STORE_NAME || 'WooCommerce Core E2E Test Suite'; +export const FOOTER_TEXT = 'Built with WooCommerce'; + export const admin_username = __ENV.A_USER || 'admin'; export const admin_password = __ENV.A_PW || 'password'; export const admin_acc_login = __ENV.A_ACC_LOGIN || false; diff --git a/plugins/woocommerce/tests/performance/headers.js b/plugins/woocommerce/tests/performance/headers.js index b73fda1b72b..0010a844b0a 100644 --- a/plugins/woocommerce/tests/performance/headers.js +++ b/plugins/woocommerce/tests/performance/headers.js @@ -1,73 +1,76 @@ +/** + * Internal dependencies + */ import { base_host, base_url } from './config.js'; const htmlRequestHeader = { - accept: - 'text/html,application/xhtml+xml,application/xml;' + - 'q=0.9,image/avif,image/webp,image/apng,*/*;' + - 'q=0.8,application/signed-exchange;v=b3;q=0.9' - }; + accept: + 'text/html,application/xhtml+xml,application/xml;' + + 'q=0.9,image/avif,image/webp,image/apng,*/*;' + + 'q=0.8,application/signed-exchange;v=b3;q=0.9', +}; const jsonRequestHeader = { - accept: 'application/json, text/javascript, */*; q=0.01' - }; + accept: 'application/json, text/javascript, */*; q=0.01', +}; const jsonAPIRequestHeader = { - accept: 'application/json, */*;q=0.1' - }; + accept: 'application/json, */*;q=0.1', +}; const allRequestHeader = { - accept: '*//*' - }; + accept: '*//*', +}; const commonRequestHeaders = { - 'accept-language': 'en-US,en;q=0.9' - }; + 'accept-language': 'en-US,en;q=0.9', +}; const commonGetRequestHeaders = { - connection: 'keep-alive', - host: `${base_host}`, - 'sec-fetch-dest': 'document', - 'sec-fetch-mode': 'navigate', - 'sec-fetch-site': 'same-origin', - 'sec-fetch-user': '?1', - 'upgrade-insecure-requests': '1' - }; + connection: 'keep-alive', + host: `${ base_host }`, + 'sec-fetch-dest': 'document', + 'sec-fetch-mode': 'navigate', + 'sec-fetch-site': 'same-origin', + 'sec-fetch-user': '?1', + 'upgrade-insecure-requests': '1', +}; const commonAPIGetRequestHeaders = { - connection: 'keep-alive', - host: `${base_host}`, - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - }; + connection: 'keep-alive', + host: `${ base_host }`, + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', +}; const contentTypeRequestHeader = { - 'content-type': 'application/x-www-form-urlencoded' - }; + 'content-type': 'application/x-www-form-urlencoded', +}; const commonPostRequestHeaders = { - origin: `${base_url}`, - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - 'x-requested-with': 'XMLHttpRequest' - }; + origin: `${ base_url }`, + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', + 'x-requested-with': 'XMLHttpRequest', +}; const commonNonStandardHeaders = { - 'sec-ch-ua': - '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', - 'sec-ch-ua-mobile': '?0' - }; + 'sec-ch-ua': + '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', + 'sec-ch-ua-mobile': '?0', +}; export { - htmlRequestHeader, - jsonRequestHeader, - jsonAPIRequestHeader, - allRequestHeader, - commonRequestHeaders, - commonGetRequestHeaders, - commonAPIGetRequestHeaders, - contentTypeRequestHeader, - commonPostRequestHeaders, - commonNonStandardHeaders, + htmlRequestHeader, + jsonRequestHeader, + jsonAPIRequestHeader, + allRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonAPIGetRequestHeaders, + contentTypeRequestHeader, + commonPostRequestHeaders, + commonNonStandardHeaders, }; diff --git a/plugins/woocommerce/tests/performance/requests/merchant/add-order.js b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js index dbda889f742..139b5ce7fbd 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/add-order.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js @@ -1,4 +1,3 @@ -/* eslint-disable no-shadow */ /* eslint-disable import/no-unresolved */ /** * External dependencies @@ -65,17 +64,15 @@ if ( hpos_status === true ) { } else { admin_new_order_base = 'post-new.php?post_type=shop_order'; admin_update_order_base = 'post.php'; - admin_new_order_assert = 'Add new order'; + admin_new_order_assert = 'Add new order'; admin_open_order_assert = 'Edit order'; admin_created_order_assert = 'Order updated.'; admin_update_order_assert = 'Order updated.'; } -const date = new Date(); -const order_date = date.toJSON().slice( 0, 10 ); +const global_order_date = new Date().toJSON().slice( 0, 10 ); export function addOrder( includeTests = {} ) { - let response; let ajax_nonce_add_meta; let wpnonce; let closed_postboxes_nonce; @@ -87,7 +84,8 @@ export function addOrder( includeTests = {} ) { let api_x_wp_nonce; let apiNonceHeader; let heartbeat_nonce; - let includedTests = Object.assign( { + const includedTests = Object.assign( + { create: true, heartbeat: true, open: true, @@ -106,7 +104,7 @@ export function addOrder( includeTests = {} ) { commonNonStandardHeaders ); - response = http.get( + const response = http.get( `${ base_url }/wp-admin/${ admin_new_order_base }`, { headers: requestHeaders, @@ -115,8 +113,8 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Add new order' header": ( response ) => - response.body.includes( `${ admin_new_order_assert }` ), + "body contains: 'Add new order' header": ( r ) => + r.body.includes( `${ admin_new_order_assert }` ), } ); // Correlate nonce values for use in subsequent requests. @@ -190,18 +188,18 @@ export function addOrder( includeTests = {} ) { commonNonStandardHeaders ); - response = http.get( + const tasksResponse = http.get( `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, { headers: requestHeaders, tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, } ); - check( response, { + check( tasksResponse, { 'is status 200': ( r ) => r.status === 200, } ); - response = http.get( + const notesResponse = http.get( `${ base_url }/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` + `type=error%2Cupdate&status=unactioned&_locale=user`, { @@ -209,11 +207,11 @@ export function addOrder( includeTests = {} ) { tags: { name: 'Merchant - wc-analytics/admin/notes?' }, } ); - check( response, { + check( notesResponse, { 'is status 200': ( r ) => r.status === 200, } ); - response = http.get( + const optionsResponse = http.get( `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, { headers: requestHeaders, @@ -222,7 +220,7 @@ export function addOrder( includeTests = {} ) { }, } ); - check( response, { + check( optionsResponse, { 'is status 200': ( r ) => r.status === 200, } ); } ); @@ -239,7 +237,7 @@ export function addOrder( includeTests = {} ) { commonNonStandardHeaders ); - response = http.post( + const response = http.post( `${ base_url }/wp-admin/admin-ajax.php`, `_nonce=${ heartbeat_nonce }&action=heartbeat&has_focus=true&interval=15&screen_id=shop_order`, { @@ -252,7 +250,9 @@ export function addOrder( includeTests = {} ) { } ); } ); - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + sleep( + randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) + ); } if ( includedTests.create ) { @@ -266,13 +266,18 @@ export function addOrder( includeTests = {} ) { commonNonStandardHeaders ); - const date = new Date(); - const order_date = date.toJSON().slice( 0, 10 ); + const order_date = new Date().toJSON().slice( 0, 10 ); const orderParams = new URLSearchParams( [ [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], - [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_billing_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_billing_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ], @@ -281,12 +286,24 @@ export function addOrder( includeTests = {} ) { '_billing_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_billing_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ], - [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_billing_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_billing_state', `${ addresses_guest_billing_state }` ], - [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_shipping_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_shipping_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ], @@ -294,9 +311,15 @@ export function addOrder( includeTests = {} ) { '_shipping_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_shipping_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], - [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_shipping_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_payment_method', `${ payment_method }` ], [ '_transaction_id', '' ], @@ -337,8 +360,14 @@ export function addOrder( includeTests = {} ) { const hposOrderParams = new URLSearchParams( [ [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], - [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_billing_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_billing_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ], @@ -347,12 +376,24 @@ export function addOrder( includeTests = {} ) { '_billing_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_billing_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ], - [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_billing_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_billing_state', `${ addresses_guest_billing_state }` ], - [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_shipping_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_shipping_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ], @@ -360,9 +401,15 @@ export function addOrder( includeTests = {} ) { '_shipping_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_shipping_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], - [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_shipping_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_payment_method', `${ payment_method }` ], [ '_transaction_id', '' ], @@ -397,7 +444,7 @@ export function addOrder( includeTests = {} ) { admin_update_order_params = orderParams.toString(); } - response = http.post( + const response = http.post( `${ base_url }/wp-admin/${ admin_update_order }`, admin_update_order_params.toString(), { @@ -407,14 +454,16 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Edit order' header": ( response ) => - response.body.includes( `${ admin_open_order_assert }` ), - "body contains: 'Order updated' confirmation": ( response ) => - response.body.includes( `${ admin_created_order_assert }` ), + "body contains: 'Edit order' header": ( r ) => + r.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Order updated' confirmation": ( r ) => + r.body.includes( `${ admin_created_order_assert }` ), } ); } ); - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + sleep( + randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) + ); } if ( includedTests.open ) { @@ -433,7 +482,7 @@ export function addOrder( includeTests = {} ) { admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; } - response = http.get( + const response = http.get( `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, { headers: requestHeaders, @@ -442,12 +491,14 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Edit order' header": ( response ) => - response.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Edit order' header": ( r ) => + r.body.includes( `${ admin_open_order_assert }` ), } ); } ); - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + sleep( + randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) + ); } if ( includedTests.update ) { @@ -463,8 +514,14 @@ export function addOrder( includeTests = {} ) { const orderParams = new URLSearchParams( [ [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], - [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_billing_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_billing_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ], @@ -473,12 +530,24 @@ export function addOrder( includeTests = {} ) { '_billing_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_billing_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ], - [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_billing_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_billing_state', `${ addresses_guest_billing_state }` ], - [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_shipping_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_shipping_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ], @@ -486,9 +555,15 @@ export function addOrder( includeTests = {} ) { '_shipping_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_shipping_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], - [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_shipping_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_payment_method', `${ payment_method }` ], [ '_transaction_id', '' ], @@ -503,7 +578,7 @@ export function addOrder( includeTests = {} ) { [ 'metakeyinput', '' ], [ 'metakeyselect', '%23NONE%23' ], [ 'metavalue', '' ], - [ 'order_date', `${ order_date }` ], + [ 'order_date', `${ global_order_date }` ], [ 'order_date_hour', '01' ], [ 'order_date_minute', '01' ], [ 'order_date_second', '01' ], @@ -528,8 +603,14 @@ export function addOrder( includeTests = {} ) { const hposOrderParams = new URLSearchParams( [ [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], - [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_billing_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_billing_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ], @@ -538,12 +619,24 @@ export function addOrder( includeTests = {} ) { '_billing_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_billing_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ], - [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_billing_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_billing_state', `${ addresses_guest_billing_state }` ], - [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], - [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ + '_shipping_address_1', + `${ addresses_guest_billing_address_1 }`, + ], + [ + '_shipping_address_2', + `${ addresses_guest_billing_address_2 }`, + ], [ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ], @@ -551,9 +644,15 @@ export function addOrder( includeTests = {} ) { '_shipping_first_name', `${ addresses_guest_billing_first_name }`, ], - [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ + '_shipping_last_name', + `${ addresses_guest_billing_last_name }`, + ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], - [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ + '_shipping_postcode', + `${ addresses_guest_billing_postcode }`, + ], [ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_payment_method', `${ payment_method }` ], [ '_transaction_id', '' ], @@ -564,7 +663,7 @@ export function addOrder( includeTests = {} ) { [ 'excerpt', '' ], [ 'metakeyinput', '' ], [ 'metavalue', '' ], - [ 'order_date', `${ order_date }` ], + [ 'order_date', `${ global_order_date }` ], [ 'order_date_hour', '01' ], [ 'order_date_minute', '01' ], [ 'order_date_second', '01' ], @@ -588,7 +687,7 @@ export function addOrder( includeTests = {} ) { admin_update_order_id = `${ admin_open_order_base }`; } - response = http.post( + const response = http.post( `${ base_url }/wp-admin/${ admin_update_order_id }`, admin_update_order_params.toString(), { @@ -598,8 +697,8 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Order updated' confirmation": ( response ) => - response.body.includes( `${ admin_update_order_assert }` ), + "body contains: 'Order updated' confirmation": ( r ) => + r.body.includes( `${ admin_update_order_assert }` ), } ); } ); } @@ -616,8 +715,7 @@ export function addOrder( includeTests = {} ) { commonNonStandardHeaders ); - const date = new Date(); - const order_date = date.toJSON().slice( 0, 10 ); + const order_date = new Date().toJSON().slice( 0, 10 ); const orderParams = new URLSearchParams( [ [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], @@ -747,7 +845,7 @@ export function addOrder( includeTests = {} ) { admin_update_order_params = orderParams.toString(); } - response = http.post( + const response = http.post( `${ base_url }/wp-admin/${ admin_update_order }`, admin_update_order_params.toString(), { @@ -757,10 +855,10 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Edit order' header": ( response ) => - response.body.includes( `${ admin_open_order_assert }` ), - "body contains: 'Order updated' confirmation": ( response ) => - response.body.includes( `${ admin_created_order_assert }` ), + "body contains: 'Edit order' header": ( r ) => + r.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Order updated' confirmation": ( r ) => + r.body.includes( `${ admin_created_order_assert }` ), } ); } ); @@ -781,7 +879,7 @@ export function addOrder( includeTests = {} ) { admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; } - response = http.get( + const response = http.get( `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, { headers: requestHeaders, @@ -790,8 +888,8 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Edit order' header": ( response ) => - response.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Edit order' header": ( r ) => + r.body.includes( `${ admin_open_order_assert }` ), } ); } ); @@ -849,7 +947,7 @@ export function addOrder( includeTests = {} ) { [ 'metakeyinput', '' ], [ 'metakeyselect', '%23NONE%23' ], [ 'metavalue', '' ], - [ 'order_date', `${ order_date }` ], + [ 'order_date', `${ global_order_date }` ], [ 'order_date_hour', '01' ], [ 'order_date_minute', '01' ], [ 'order_date_second', '01' ], @@ -910,7 +1008,7 @@ export function addOrder( includeTests = {} ) { [ 'excerpt', '' ], [ 'metakeyinput', '' ], [ 'metavalue', '' ], - [ 'order_date', `${ order_date }` ], + [ 'order_date', `${ global_order_date }` ], [ 'order_date_hour', '01' ], [ 'order_date_minute', '01' ], [ 'order_date_second', '01' ], @@ -934,7 +1032,7 @@ export function addOrder( includeTests = {} ) { admin_update_order_id = `${ admin_open_order_base }`; } - response = http.post( + const response = http.post( `${ base_url }/wp-admin/${ admin_update_order_id }`, admin_update_order_params.toString(), { @@ -944,11 +1042,11 @@ export function addOrder( includeTests = {} ) { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Order updated' confirmation": ( response ) => - response.body.includes( `${ admin_update_order_assert }` ), + "body contains: 'Order updated' confirmation": ( r ) => + r.body.includes( `${ admin_update_order_assert }` ), } ); } ); -}; +} export default function () { addOrder(); diff --git a/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js b/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js index f4ac2d8b7cd..240a15c9b84 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js @@ -27,7 +27,8 @@ export function homeWCAdmin( includeTests = {} ) { let response; let api_x_wp_nonce; let apiNonceHeader; - let includedTests = Object.assign( { + const includedTests = Object.assign( + { orders: true, other: true, products: true, @@ -51,8 +52,8 @@ export function homeWCAdmin( includeTests = {} ) { } ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: current page is 'Home'": ( response ) => - response.body.includes( 'aria-current="page">Home' ), + "body contains: current page is 'Home'": ( r ) => + r.body.includes( 'aria-current="page">Home' ), } ); // Correlate nonce values for use in subsequent requests. diff --git a/plugins/woocommerce/tests/performance/requests/shopper/cart-apply-coupon.js b/plugins/woocommerce/tests/performance/requests/shopper/cart-apply-coupon.js index 89007965f15..4e43a1bb3df 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/cart-apply-coupon.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/cart-apply-coupon.js @@ -1,4 +1,3 @@ -/* eslint-disable no-shadow */ /* eslint-disable import/no-unresolved */ /** * External dependencies @@ -32,7 +31,6 @@ import { } from '../../headers.js'; export function cartApplyCoupon() { - let response; let apply_coupon_nonce; // let item_name; let woocommerce_cart_nonce; @@ -46,7 +44,7 @@ export function cartApplyCoupon() { commonNonStandardHeaders ); - response = http.post( + const response = http.post( `${ base_url }/?wc-ajax=add_to_cart`, { product_sku: `${ product_sku }`, @@ -74,15 +72,14 @@ export function cartApplyCoupon() { commonNonStandardHeaders ); - response = http.get( `${ base_url }/cart`, { + const response = http.get( `${ base_url }/cart`, { headers: requestheaders, tags: { name: 'Shopper - View Cart' }, } ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body does not contain: 'your cart is currently empty'": ( - response - ) => ! response.body.includes( 'Your cart is currently empty.' ), + "body does not contain: 'your cart is currently empty'": ( r ) => + ! r.body.includes( 'Your cart is currently empty.' ), } ); // Correlate cart item value for use in subsequent requests. @@ -111,7 +108,7 @@ export function cartApplyCoupon() { contentTypeRequestHeader ); - response = http.post( + const response = http.post( `${ base_url }/?wc-ajax=apply_coupon`, { coupon_code: `${ coupon_code }`, @@ -125,11 +122,11 @@ export function cartApplyCoupon() { check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'Coupon code applied successfully'": ( response ) => - response.body.includes( 'Coupon code applied successfully' ), + "body contains: 'Coupon code applied successfully'": ( r ) => + r.body.includes( 'Coupon code applied successfully' ), } ); - response = http.post( + const cartResponse = http.post( `${ base_url }/cart`, { _wp_http_referer: '%2Fcart', @@ -142,10 +139,10 @@ export function cartApplyCoupon() { tags: { name: 'Shopper - Update Cart' }, } ); - check( response, { + check( cartResponse, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'woocommerce-remove-coupon' class": ( response ) => - response.body.includes( 'class="woocommerce-remove-coupon"' ), + "body contains: 'woocommerce-remove-coupon' class": ( r ) => + r.body.includes( 'class="woocommerce-remove-coupon"' ), } ); } ); diff --git a/plugins/woocommerce/tests/performance/requests/shopper/cart-remove-item.js b/plugins/woocommerce/tests/performance/requests/shopper/cart-remove-item.js index 355942e4ce4..c76b0444e0e 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/cart-remove-item.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/cart-remove-item.js @@ -1,5 +1,4 @@ -/* eslint-disable no-shadow */ -/* eslint-disable import/no-unresolved */ +// eslint-disable import/no-unresolved /** * External dependencies */ @@ -30,7 +29,6 @@ import { } from '../../headers.js'; export function cartRemoveItem() { - let response; let item_to_remove; let wpnonce; @@ -43,7 +41,7 @@ export function cartRemoveItem() { commonNonStandardHeaders ); - response = http.post( + const response = http.post( `${ base_url }/?wc-ajax=add_to_cart`, { product_sku: `${ product_sku }`, @@ -71,15 +69,14 @@ export function cartRemoveItem() { commonNonStandardHeaders ); - response = http.get( `${ base_url }/cart`, { + const response = http.get( `${ base_url }/cart`, { headers: requestheaders, tags: { name: 'Shopper - View Cart' }, } ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body does not contain: 'your cart is currently empty'": ( - response - ) => ! response.body.includes( 'Your cart is currently empty.' ), + "body does not contain: 'your cart is currently empty'": ( r ) => + ! r.body.includes( 'Your cart is currently empty.' ), } ); // Correlate cart item value for use in subsequent requests. @@ -98,7 +95,7 @@ export function cartRemoveItem() { commonNonStandardHeaders ); - response = http.get( + const response = http.get( `${ base_url }/cart?remove_item=${ item_to_remove }&_wpnonce=${ wpnonce }`, { headers: requestheaders, @@ -107,8 +104,7 @@ export function cartRemoveItem() { ); check( response, { 'is status 200': ( r ) => r.status === 200, - "body contains: 'removed'": ( response ) => - response.body.includes( ' removed.' ), + "body contains: 'removed'": ( r ) => r.body.includes( ' removed.' ), } ); } ); diff --git a/plugins/woocommerce/tests/performance/requests/shopper/cart.js b/plugins/woocommerce/tests/performance/requests/shopper/cart.js index 21f38e2956b..279cf18635c 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/cart.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/cart.js @@ -1,4 +1,3 @@ -/* eslint-disable no-shadow */ /* eslint-disable import/no-unresolved */ /** * External dependencies @@ -16,6 +15,8 @@ import { product_id, think_time_min, think_time_max, + STORE_NAME, + FOOTER_TEXT, } from '../../config.js'; import { htmlRequestHeader, @@ -27,8 +28,6 @@ import { } from '../../headers.js'; export function cart() { - let response; - group( 'Product Page Add to cart', function () { const requestheaders = Object.assign( {}, @@ -38,7 +37,7 @@ export function cart() { commonNonStandardHeaders ); - response = http.post( + const response = http.post( `${ base_url }/?wc-ajax=add_to_cart`, { product_sku: `${ product_sku }`, @@ -66,26 +65,19 @@ export function cart() { commonNonStandardHeaders ); - response = http.get( `${ base_url }/cart`, { + const response = http.get( `${ base_url }/cart`, { headers: requestheaders, tags: { name: 'Shopper - View Cart' }, } ); check( response, { 'is status 200': ( r ) => r.status === 200, - 'title is: "Cart – WooCommerce Core E2E Test Suite"': ( - response - ) => - response.html().find( 'head title' ).text() === - 'Cart – WooCommerce Core E2E Test Suite', - "body does not contain: 'your cart is currently empty'": ( - response - ) => ! response.body.includes( 'Your cart is currently empty.' ), - 'footer contains: Built with WooCommerce': ( response ) => - response - .html() - .find( 'body footer' ) - .text() - .includes( 'Built with WooCommerce' ), + [ `title is: "Cart – ${ STORE_NAME }"` ]: ( r ) => + r.html().find( 'head title' ).text() === + `Cart – ${ STORE_NAME }`, + "body does not contain: 'your cart is currently empty'": ( r ) => + ! r.body.includes( 'Your cart is currently empty.' ), + 'footer contains: Built with WooCommerce': ( r ) => + r.html().find( 'body footer' ).text().includes( FOOTER_TEXT ), } ); } ); diff --git a/plugins/woocommerce/tests/performance/requests/shopper/category-page.js b/plugins/woocommerce/tests/performance/requests/shopper/category-page.js index e5be767659b..f9495898848 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/category-page.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/category-page.js @@ -1,9 +1,8 @@ -/* eslint-disable no-shadow */ /* eslint-disable import/no-unresolved */ /** * External dependencies */ -import { sleep, check, group } from 'k6'; +import { sleep, group } from 'k6'; import http from 'k6/http'; import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; @@ -15,6 +14,8 @@ import { think_time_min, think_time_max, product_category, + FOOTER_TEXT, + STORE_NAME, } from '../../config.js'; import { htmlRequestHeader, @@ -22,6 +23,7 @@ import { commonGetRequestHeaders, commonNonStandardHeaders, } from '../../headers.js'; +import { checkResponse } from '../../utils.js'; export function categoryPage() { let response; @@ -42,23 +44,10 @@ export function categoryPage() { tags: { name: 'Shopper - Category Page' }, } ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - 'title is: "Accessories – WooCommerce Core E2E Test Suite"': ( - response - ) => - response.html().find( 'head title' ).text() === - 'Accessories – WooCommerce Core E2E Test Suite', - "body contains: Category's title": ( response ) => - response.body.includes( - `