From b1990cfb85583af95b23a684bc215be4b129ca14 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 30 Aug 2021 13:23:54 -0600 Subject: [PATCH] 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. + } +}