From efbb119b31450ea815346795e497ccca4ad084b8 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 27 Aug 2021 15:59:44 -0600 Subject: [PATCH 1/9] Get environment context for tests --- tests/e2e/config/jest.setup.js | 11 +++++++++++ tests/e2e/utils/src/flows/with-rest-api.js | 23 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index ebf80556653..70235642d2b 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -35,6 +35,15 @@ async function trashExistingPosts() { } } +/** + * Uses the WooCommerce API to get the envivonment context. + */ +async function getEnvironmentContext() { + const environment = await withRestApi.getSystemEnvironment(); + process.env.WORDPRESS_VERSION = environment.wp_version; + process.env.WC_VERSION = environment.version; +} + // Before every test suite run, delete all content created by the test. This ensures // other posts/comments/etc. aren't dirtying tests and tests don't depend on // each other's side-effects. @@ -46,6 +55,8 @@ beforeAll(async () => { } try { + await getEnvironmentContext(); + // Update the ready page to prevent concurrent test runs await updateReadyPageStatus('draft'); await trashExistingPosts(); diff --git a/tests/e2e/utils/src/flows/with-rest-api.js b/tests/e2e/utils/src/flows/with-rest-api.js index 7bc1d08cf00..ea6a96e0ac5 100644 --- a/tests/e2e/utils/src/flows/with-rest-api.js +++ b/tests/e2e/utils/src/flows/with-rest-api.js @@ -6,6 +6,7 @@ const onboardingProfileEndpoint = '/wc-admin/onboarding/profile'; const shippingZoneEndpoint = '/wc/v3/shipping/zones'; const shippingClassesEndpoint = '/wc/v3/products/shipping_classes'; const userEndpoint = '/wp/v2/users'; +const systemStatusEndpoint = '/wc/v3/system_status'; /** * Utility function to delete all merchant created data store objects. @@ -252,18 +253,32 @@ export const withRestApi = { } } }, - + /** * Create a batch of orders using the "Batch Create Order" API endpoint. - * + * * @param orders Array of orders to be created */ - batchCreateOrders : async (orders) => { + batchCreateOrders: async (orders) => { const path = '/wc/v3/orders/batch'; const payload = { create: orders }; - + const { statusCode } = await client.post(path, payload); expect(statusCode).toEqual(200); + }, + + /** + * Get the current envrionment from the WooCommerce system status API. + * + * @returns {Promise} The environment object from the API response. + */ + getSystemEnvironment: async () => { + const response = await client.get( systemStatusEndpoint ); + if ( response.data.environment ) { + return response.data.environment + } else { + return; + } } }; From 0f1325d93789f86b774d77c55872601678721359 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 27 Aug 2021 16:04:03 -0600 Subject: [PATCH 2/9] Added changelog and readme --- tests/e2e/utils/CHANGELOG.md | 1 + tests/e2e/utils/README.md | 1 + tests/e2e/utils/src/flows/with-rest-api.js | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e/utils/CHANGELOG.md b/tests/e2e/utils/CHANGELOG.md index 59941993f75..0c5e97ef1db 100644 --- a/tests/e2e/utils/CHANGELOG.md +++ b/tests/e2e/utils/CHANGELOG.md @@ -19,6 +19,7 @@ - Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses - Added `createOrder()` component util that creates an order using the API with the passed in details - Updated `addShippingZoneAndMethod` to use the API instead of UI to create shipping zones +- Added `getSystemEnvironment()` that gets the current environment from the WooCommerce API. # 0.1.5 diff --git a/tests/e2e/utils/README.md b/tests/e2e/utils/README.md index 32cfe13a5ee..da016482463 100644 --- a/tests/e2e/utils/README.md +++ b/tests/e2e/utils/README.md @@ -149,6 +149,7 @@ This package provides support for enabling retries in tests: | `resetSettingsGroupToDefault` | `settingsGroup` | Reset settings in settings group to default except `select` fields | | `batchCreateOrders` | `orders` | Create a batch of orders using the "Batch Create Order" API endpoint | | `deleteAllOrders` | | Permanently delete all orders | +| `getSystemEnvironment| | Get the current environment from the WooCommerce system status API. ### Page Utilities diff --git a/tests/e2e/utils/src/flows/with-rest-api.js b/tests/e2e/utils/src/flows/with-rest-api.js index ea6a96e0ac5..349c7d22218 100644 --- a/tests/e2e/utils/src/flows/with-rest-api.js +++ b/tests/e2e/utils/src/flows/with-rest-api.js @@ -269,7 +269,7 @@ export const withRestApi = { }, /** - * Get the current envrionment from the WooCommerce system status API. + * Get the current environment from the WooCommerce system status API. * * @returns {Promise} The environment object from the API response. */ From e496f5ef1598fbd6073d528fd90565db25542316 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 27 Aug 2021 16:07:55 -0600 Subject: [PATCH 3/9] Minor fix to README --- tests/e2e/utils/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/README.md b/tests/e2e/utils/README.md index da016482463..b1687b202c2 100644 --- a/tests/e2e/utils/README.md +++ b/tests/e2e/utils/README.md @@ -149,7 +149,7 @@ This package provides support for enabling retries in tests: | `resetSettingsGroupToDefault` | `settingsGroup` | Reset settings in settings group to default except `select` fields | | `batchCreateOrders` | `orders` | Create a batch of orders using the "Batch Create Order" API endpoint | | `deleteAllOrders` | | Permanently delete all orders | -| `getSystemEnvironment| | Get the current environment from the WooCommerce system status API. +| `getSystemEnvironment` | | Get the current environment from the WooCommerce system status API. ### Page Utilities From a688716587a351297421fe5d404d0028863b9268 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 27 Aug 2021 16:08:33 -0600 Subject: [PATCH 4/9] Remove extra whitespace --- tests/e2e/config/jest.setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index 70235642d2b..4811a8d7e77 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -39,7 +39,7 @@ async function trashExistingPosts() { * Uses the WooCommerce API to get the envivonment context. */ async function getEnvironmentContext() { - const environment = await withRestApi.getSystemEnvironment(); + const environment = await withRestApi.getSystemEnvironment(); process.env.WORDPRESS_VERSION = environment.wp_version; process.env.WC_VERSION = environment.version; } From 9234fb7f3bf0ec2b760ae6681647e9f3bb42b460 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 27 Aug 2021 17:36:39 -0600 Subject: [PATCH 5/9] Fix typo --- tests/e2e/config/jest.setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index 4811a8d7e77..3d4435cbe3a 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -36,7 +36,7 @@ async function trashExistingPosts() { } /** - * Uses the WooCommerce API to get the envivonment context. + * Uses the WooCommerce API to get the environment context. */ async function getEnvironmentContext() { const environment = await withRestApi.getSystemEnvironment(); From 7276a4e48929104b04d3c7d88a88a5541bb4520c Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 30 Aug 2021 10:33:45 -0600 Subject: [PATCH 6/9] Code review feedback --- tests/e2e/config/jest.setup.js | 8 ++++---- .../shopper/front-end-product-browse-search-sort.test.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index 3d4435cbe3a..c8b2bcb91fb 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -36,11 +36,11 @@ async function trashExistingPosts() { } /** - * Uses the WooCommerce API to get the environment context. + * Uses the WooCommerce API to set the environment context. */ -async function getEnvironmentContext() { +async function setEnvironmentContext() { const environment = await withRestApi.getSystemEnvironment(); - process.env.WORDPRESS_VERSION = environment.wp_version; + process.env.WP_VERSION = environment.wp_version; process.env.WC_VERSION = environment.version; } @@ -55,7 +55,7 @@ beforeAll(async () => { } try { - await getEnvironmentContext(); + await setEnvironmentContext(); // Update the ready page to prevent concurrent test runs await updateReadyPageStatus('draft'); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js b/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js index 73f2cefd042..c8b151bf9af 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js @@ -15,7 +15,7 @@ const { describe, beforeAll, } = require( '@jest/globals' ); -const { WORDPRESS_VERSION } = process.env; +const { WP_VERSION } = process.env; const config = require( 'config' ); const simpleProductName = config.get( 'products.simple.name' ); @@ -28,7 +28,7 @@ const hardware = 'Hardware'; const productTitle = 'li.first > a > h2.woocommerce-loop-product__title'; const runProductBrowseSearchSortTest = () => { - utils.describeIf( WORDPRESS_VERSION >= '5.8' )( 'Search, browse by categories and sort items in the shop', () => { + utils.describeIf( WP_VERSION >= '5.8' )( 'Search, browse by categories and sort items in the shop', () => { beforeAll(async () => { // Create 1st product with Clothing category await createSimpleProductWithCategory(simpleProductName + ' 1', singleProductPrice, clothing); From eaed316450c1baff4bc56b4dd312131b4f0f0758 Mon Sep 17 00:00:00 2001 From: Greg <71906536+zhongruige@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:00:54 -0600 Subject: [PATCH 7/9] Added missing semicolon --- tests/e2e/utils/src/flows/with-rest-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/src/flows/with-rest-api.js b/tests/e2e/utils/src/flows/with-rest-api.js index 349c7d22218..d99c5262c2f 100644 --- a/tests/e2e/utils/src/flows/with-rest-api.js +++ b/tests/e2e/utils/src/flows/with-rest-api.js @@ -276,7 +276,7 @@ export const withRestApi = { getSystemEnvironment: async () => { const response = await client.get( systemStatusEndpoint ); if ( response.data.environment ) { - return response.data.environment + return response.data.environment; } else { return; } From b1990cfb85583af95b23a684bc215be4b129ca14 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 30 Aug 2021 13:23:54 -0600 Subject: [PATCH 8/9] Code review feedback --- tests/e2e/config/jest.setup.js | 11 ----------- .../front-end-product-browse-search-sort.test.js | 9 +++++++-- tests/e2e/utils/src/flows/with-rest-api.js | 2 ++ tests/e2e/utils/src/index.js | 1 + tests/e2e/utils/src/system-environment.js | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 tests/e2e/utils/src/system-environment.js diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index c8b2bcb91fb..ebf80556653 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -35,15 +35,6 @@ async function trashExistingPosts() { } } -/** - * Uses the WooCommerce API to set the environment context. - */ -async function setEnvironmentContext() { - const environment = await withRestApi.getSystemEnvironment(); - process.env.WP_VERSION = environment.wp_version; - process.env.WC_VERSION = environment.version; -} - // Before every test suite run, delete all content created by the test. This ensures // other posts/comments/etc. aren't dirtying tests and tests don't depend on // each other's side-effects. @@ -55,8 +46,6 @@ beforeAll(async () => { } try { - await setEnvironmentContext(); - // Update the ready page to prevent concurrent test runs await updateReadyPageStatus('draft'); await trashExistingPosts(); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js b/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js index c8b151bf9af..a0a1a298582 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-product-browse-search-sort.test.js @@ -5,6 +5,7 @@ const { shopper, createSimpleProductWithCategory, utils, + getEnvironmentContext, } = require( '@woocommerce/e2e-utils' ); /** @@ -15,7 +16,6 @@ const { describe, beforeAll, } = require( '@jest/globals' ); -const { WP_VERSION } = process.env; const config = require( 'config' ); const simpleProductName = config.get( 'products.simple.name' ); @@ -27,8 +27,13 @@ const audio = 'Audio'; const hardware = 'Hardware'; const productTitle = 'li.first > a > h2.woocommerce-loop-product__title'; +const getWordPressVersion = async () => { + const context = await getEnvironmentContext(); + return context.wpVersion; +} + const runProductBrowseSearchSortTest = () => { - utils.describeIf( WP_VERSION >= '5.8' )( 'Search, browse by categories and sort items in the shop', () => { + utils.describeIf( getWordPressVersion() >= 5.8 )( 'Search, browse by categories and sort items in the shop', () => { beforeAll(async () => { // Create 1st product with Clothing category await createSimpleProductWithCategory(simpleProductName + ' 1', singleProductPrice, clothing); diff --git a/tests/e2e/utils/src/flows/with-rest-api.js b/tests/e2e/utils/src/flows/with-rest-api.js index 349c7d22218..ae4eb931be9 100644 --- a/tests/e2e/utils/src/flows/with-rest-api.js +++ b/tests/e2e/utils/src/flows/with-rest-api.js @@ -271,6 +271,8 @@ export const withRestApi = { /** * Get the current environment from the WooCommerce system status API. * + * For more details, see: https://woocommerce.github.io/woocommerce-rest-api-docs/#system-status-environment-properties + * * @returns {Promise} The environment object from the API response. */ getSystemEnvironment: async () => { diff --git a/tests/e2e/utils/src/index.js b/tests/e2e/utils/src/index.js index 6b5c918db7f..8a9b6f1af19 100644 --- a/tests/e2e/utils/src/index.js +++ b/tests/e2e/utils/src/index.js @@ -11,3 +11,4 @@ export * from './flows'; export * from './old-flows'; export * from './components'; export * from './page-utils'; +export * from './system-environment'; diff --git a/tests/e2e/utils/src/system-environment.js b/tests/e2e/utils/src/system-environment.js new file mode 100644 index 00000000000..37a6c85937b --- /dev/null +++ b/tests/e2e/utils/src/system-environment.js @@ -0,0 +1,16 @@ +import { withRestApi } from './flows'; + +/** + * Uses the WooCommerce API to get the environment context. + */ +export const getEnvironmentContext = async () => { + try { + const environment = await withRestApi.getSystemEnvironment(); + return { + wpVersion: environment.wp_version, + wcVersion: environment.version, + } + } catch ( error ) { + // Prevent an error here causing tests to fail. + } +} From a130109445a9950e2d27d7d7ad14fd2a754f021b Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 30 Aug 2021 14:22:23 -0600 Subject: [PATCH 9/9] Skip WCCOM connection --- .../specs/merchant/wp-admin-extensions-connect-wccom.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-extensions-connect-wccom.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-extensions-connect-wccom.test.js index dfa305ca599..3935b7743de 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-extensions-connect-wccom.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-extensions-connect-wccom.test.js @@ -20,7 +20,7 @@ const runInitiateWccomConnectionTest = () => { await merchant.login(); }); - it('can initiate WCCOM connection', async () => { + it.skip('can initiate WCCOM connection', async () => { await merchant.openHelper(); // Click on Connect button to initiate a WCCOM connection