Merge branch 'trunk' into e2e/add-build-to-e2e-core-tests

This commit is contained in:
Lucas Bustamante 2022-01-04 16:00:02 -03:00
commit 2e1a021195
42 changed files with 161 additions and 79 deletions

View File

@ -13,10 +13,10 @@ jobs:
steps:
- name: Create dirs.
run: |
mkdir -p code/woocommerce
mkdir -p package/woocommerce
mkdir -p tmp/woocommerce
mkdir -p node_modules
mkdir -p code/woocommerce
mkdir -p package/woocommerce
mkdir -p tmp/woocommerce
mkdir -p node_modules
- name: Checkout code.
uses: actions/checkout@v2
@ -35,7 +35,7 @@ jobs:
- name: Run smoke test.
working-directory: package/woocommerce/plugins/woocommerce
if: steps.installation.outcome == 'success'
if: always()
env:
SMOKE_TEST_URL: ${{ secrets.SMOKE_TEST_URL }}
SMOKE_TEST_ADMIN_USER: ${{ secrets.SMOKE_TEST_ADMIN_USER }}
@ -66,7 +66,7 @@ jobs:
- name: Run E2E tests.
working-directory: package/woocommerce/plugins/woocommerce
if: steps.installation.outcome == 'success'
if: always()
env:
SMOKE_TEST_URL: ${{ secrets.SMOKE_TEST_URL }}
SMOKE_TEST_ADMIN_USER: ${{ secrets.SMOKE_TEST_ADMIN_USER }}
@ -96,7 +96,7 @@ jobs:
await script({github, context})
- name: Remove label from pull request.
if: "${{ contains(github.event.pull_request.labels.*.name, 'run: smoke tests') }}"
if: always() && ${{ contains(github.event.label.name, format( 'run{0} smoke tests', ':') ) }}
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,5 +1,12 @@
# Unreleased
## Changes
- Removed the node-config dependency
## Fixed
- Moved `merchant.login()` out of `beforeAll()` block and into test body for retried runs.
## Added
- This package is now transpiled with Babel, which allows the usage of modern, yet compatible JS code.

View File

@ -13,7 +13,6 @@
"dependencies": {
"@jest/globals": "^26.4.2",
"@wordpress/deprecated": "^3.2.3",
"config": "3.3.3",
"faker": "^5.1.0"
},
"devDependencies": {
@ -31,7 +30,8 @@
},
"peerDependencies": {
"@woocommerce/api": "^0.2.0",
"@woocommerce/e2e-utils": "^0.1.6"
"@woocommerce/e2e-utils": "^0.1.6",
"@woocommerce/e2e-environment": "^0.2.3"
},
"publishConfig": {
"access": "public"

View File

@ -12,7 +12,7 @@ const {
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
import deprecated from '@wordpress/deprecated';
const {
it,

View File

@ -6,7 +6,7 @@ const { HTTPClientFactory, Coupon } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const { it, describe, beforeAll } = require( '@jest/globals' );
/**

View File

@ -6,7 +6,7 @@ const { HTTPClientFactory, ExternalProduct } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const { it, describe, beforeAll } = require( '@jest/globals' );
/**

View File

@ -10,7 +10,7 @@ const {
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const { it, describe, beforeAll } = require( '@jest/globals' );
/**

View File

@ -6,7 +6,7 @@ const { HTTPClientFactory, Order } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const { it, describe, beforeAll } = require( '@jest/globals' );
/**

View File

@ -6,7 +6,7 @@ const { HTTPClientFactory } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const { it, describe, beforeAll } = require( '@jest/globals' );
/**

View File

@ -7,7 +7,7 @@ const { HTTPClientFactory, VariableProduct, ProductVariation } = require( '@wooc
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const {
it,
describe,

View File

@ -11,8 +11,8 @@ const {
utils,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const discountedPrice = simpleProductPrice - 5.00;
const couponDialogMessage = 'Enter a coupon code to apply. Discounts are applied to line totals, before taxes.';

View File

@ -9,9 +9,9 @@ const {
} = require( '@woocommerce/e2e-utils' );
// TODO create a function for the logic below getConfigSimpleProduct(), see: https://github.com/woocommerce/woocommerce/issues/29072
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const simpleProductPrice = config.has( 'products.simple.price' ) ? config.get( 'products.simple.price' ) : '9.99';
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const runMerchantOrdersCustomerPaymentPage = () => {
let orderId;

View File

@ -9,10 +9,10 @@ const {
deleteAllEmailLogs,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const customerEmail = config.get( 'addresses.customer.billing.email' );
const adminEmail = config.has( 'users.admin.email' ) ? config.get( 'users.admin.email' ) : 'admin@woocommercecoree2etestsuite.com';
const storeName = 'WooCommerce Core E2E Test Suite';
const adminEmail = config.get( 'users.admin.email', 'admin@woocommercecoree2etestsuite.com' );
const storeName = config.get( 'storeName', 'WooCommerce Core E2E Test Suite' );
let orderId;

View File

@ -7,7 +7,7 @@ const {
withRestApi,
AdminEdit,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const {
HTTPClientFactory,
VariableProduct,

View File

@ -12,8 +12,8 @@ const {
clickAndWaitForSelector,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const runRefundOrderTest = () => {
describe('WooCommerce Orders > Refund an order', () => {

View File

@ -1,8 +1,6 @@
/**
* Internal dependencies
*/
const config = require( 'config' );
const {
merchant,
withRestApi,

View File

@ -23,13 +23,12 @@ const {
const {
it,
describe,
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const VirtualProductName = 'Virtual Product Name';
const NonVirtualProductName = 'Non-Virtual Product Name';
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const openNewProductAndVerify = async () => {
// Go to "add product" page
@ -41,10 +40,6 @@ const openNewProductAndVerify = async () => {
const runAddSimpleProductTest = () => {
describe('Add New Simple Product Page', () => {
beforeAll(async () => {
await merchant.login();
});
it('can create simple virtual product and add it to the cart', async () => {
// @todo: remove this once https://github.com/woocommerce/woocommerce/issues/31337 has been addressed
@ -53,6 +48,7 @@ const runAddSimpleProductTest = () => {
height: 700,
} );
await merchant.login();
await openNewProductAndVerify();
// Set product data and publish the product
@ -120,11 +116,8 @@ const runAddSimpleProductTest = () => {
const runAddVariableProductTest = () => {
describe('Add New Variable Product Page', () => {
beforeAll(async () => {
await merchant.login();
});
it('can create product with variations', async () => {
await merchant.login();
await openNewProductAndVerify();
// Set product data

View File

@ -8,9 +8,9 @@ const {
createSimpleProduct
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const runProductSearchTest = () => {
describe('Products > Search and View a product', () => {

View File

@ -21,8 +21,8 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const simpleProductPrice = config.has( 'products.simple.price' ) ? config.get( 'products.simple.price' ) : '9.99';
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const california = 'state:US:CA';
const sanFranciscoZIP = '94107';
const shippingZoneNameUS = 'US with Flat rate';

View File

@ -18,8 +18,8 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const firstProductPrice = config.has( 'products.simple.price' ) ? config.get( 'products.simple.price' ) : '9.99';
const { config } = require( '@woocommerce/e2e-environment' );
const firstProductPrice = config.get( 'products.simple.price', '9.99' );
const secondProductPrice = '4.99';
const fourProductPrice = firstProductPrice * 4;
var twoProductsPrice = (+firstProductPrice) + (+secondProductPrice);

View File

@ -21,7 +21,7 @@
afterAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const runCartRedirectionTest = () => {

View File

@ -17,9 +17,9 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const singleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const singleProductPrice = config.get( 'products.simple.price', '9.99' );
const twoProductPrice = singleProductPrice * 2;
const runCartPageTest = () => {

View File

@ -21,7 +21,7 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const customerBilling = config.get( 'addresses.customer.billing' );
const runCheckoutCreateAccountTest = () => {

View File

@ -19,7 +19,7 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require('config');
const { config } = require( '@woocommerce/e2e-environment' );
const runCheckoutLoginAccountTest = () => {
describe('Shopper Checkout Login Account', () => {

View File

@ -9,9 +9,9 @@ const {
uiUnblocked,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const singleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const singleProductPrice = config.get( 'products.simple.price', '9.99' );
const twoProductPrice = singleProductPrice * 2;
const threeProductPrice = singleProductPrice * 3;
const fourProductPrice = singleProductPrice * 4;

View File

@ -11,7 +11,7 @@ const {
let simplePostIdValue;
let orderNum;
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const runMyAccountPayOrderTest = () => {

View File

@ -12,7 +12,7 @@
let simplePostIdValue;
let orderId;
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const customerEmail = config.get( 'addresses.customer.billing.email' );
const storeName = 'WooCommerce Core E2E Test Suite';

View File

@ -17,11 +17,11 @@ const {
beforeAll,
} = require( '@jest/globals' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const simpleProductName = config.get( 'products.simple.name' );
const singleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const singleProductPrice2 = config.has('products.simple.price') ? '1' + singleProductPrice : '19.99';
const singleProductPrice3 = config.has('products.simple.price') ? '2' + singleProductPrice : '29.99';
const singleProductPrice = config.get( 'products.simple.price', '9.99' );
const singleProductPrice2 = '1' + singleProductPrice;
const singleProductPrice3 = '2' + singleProductPrice;
const clothing = 'Clothing';
const audio = 'Audio';
const hardware = 'Hardware';

View File

@ -9,7 +9,7 @@ const {
uiUnblocked
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
// Variables for simple product
const simpleProductName = config.get( 'products.simple.name' );
@ -20,7 +20,7 @@ const defaultVariableProduct = config.get( 'products.variable' );
let variableProductId;
// Variables for grouped product
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
const simpleProductPrice = config.get( 'products.simple.price', '9.99' );
const simple1 = {
name: simpleProductName + ' 1',
regularPrice: simpleProductPrice

View File

@ -6,7 +6,7 @@ const {
shopper,
createVariableProduct,
} = require( '@woocommerce/e2e-utils' );
const config = require('config');
const { config } = require( '@woocommerce/e2e-environment' );
let variablePostIdValue;

View File

@ -1,5 +1,11 @@
# Unreleased
## Added
- Added a `config` export to the `@woocommerce/e2e-environment` package that has all data and methods of the [config](https://github.com/lorenwest/node-config) package
- it provides its own `get()` method that accepts an optional default parameter to be used if the property is not found in the config file.
## Added
- Added `post-results-to-github-pr.js` to post smoke test results to a GitHub PR.

View File

@ -98,6 +98,22 @@ The E2E environment has the following methods to let us control Jest's overall b
E2E_RETRY_TIMES=2 pnpx wc-e2e test:e2e
```
### Default Environment Configurations
The E2E environment exports a config object which provides all the functionality of the [config](https://www.npmjs.com/package/config) package along with extending the `get` method to accept an optional second argument that will be used if the property is not found in the config file.
```js
const { config } = require( '@woocommerce/e2e-environment' );
// 'users.admin.email' doesn't exist
const adminEmail = config.get( 'users.admin.email', 'admin@woocommercecoree2etestsuite.com' );
console.log( adminEmail );
// admin@woocommercecoree2etestsuite.com
```
**Note**: If the default parameter is not found and no optional parameter is provided, an error will be thrown.
#### Test Screenshots
The test sequencer provides a screenshot function for test failures. To enable screenshots on test failure use

View File

@ -0,0 +1,32 @@
/**
* External Dependencies
*/
const config = require( 'config' );
/**
* Since the 'config' object is not extensible, we create an empty 'e2eConfig' object and map
* its prototype to the 'config' object. This allows us to extend the new 'e2eConfig' object
* while still having access to all the data and methods of 'config'
*/
const e2eConfig = Object.create( config );
/**
*
* @param property { string } - the property to be fetched from the config file
* @param defaultValue { string | number | boolean | null } - default value if 'property' is not found
* @returns { string | number | boolean }
* @throws Error
*/
e2eConfig.get = ( property, defaultValue = null ) => {
if ( config.has( property ) ) {
return config.get( property );
} else if ( defaultValue ) {
return defaultValue;
}
throw new Error(
`Configuration property "${ property }" is not defined and no defaultValue has been provided`
);
};
module.exports = e2eConfig;

View File

@ -1,6 +1,7 @@
/**
* Internal dependencies
*/
const config = require('./config');
const jestConfig = require( './jest.config' );
const jestPuppeteerConfig = require( './jest-puppeteer.config' );
const jestobjectConfig = require('./jest-object.config');
@ -12,6 +13,7 @@ const {
} = require( './use-config' );
module.exports = {
config,
jestConfig,
...jestobjectConfig,
jestPuppeteerConfig,

View File

@ -1,4 +1,9 @@
# Unreleased
## Changes
- Removed node-config dependency
- Added @woocommerce/e2e-environment peerDependency
- Updated the package to use the custom node-config object from @woocommerce/e2e-environment
## Fixed

View File

@ -14,7 +14,6 @@
"@automattic/puppeteer-utils": "github:Automattic/puppeteer-utils#0f3ec50",
"@wordpress/deprecated": "^3.2.3",
"@wordpress/e2e-test-utils": "^4.16.1",
"config": "3.3.3",
"faker": "^5.1.0",
"fishery": "^1.2.0"
},
@ -35,7 +34,8 @@
"eslint": "^8.1.0"
},
"peerDependencies": {
"@woocommerce/api": "^0.2.0"
"@woocommerce/api": "^0.2.0",
"@woocommerce/e2e-environment": "^0.2.3"
},
"publishConfig": {
"access": "public"

View File

@ -1,5 +1,5 @@
import { HTTPClientFactory } from '@woocommerce/api';
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
import { simpleProductFactory } from './factories/simple-product';
import { variableProductFactory } from './factories/variable-product';
import { variationFactory } from './factories/variation';

View File

@ -1,7 +1,7 @@
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
const baseUrl = config.get( 'url' );
/**

View File

@ -1,7 +1,7 @@
/**
* External dependencies
*/
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
/**
* Internal dependencies
@ -440,10 +440,9 @@ const merchant = {
*/
collapseAdminMenu: async ( collapse = true ) => {
const collapseButton = await page.$( '.folded #collapse-button' );
if ( ( ! collapseButton ) == collapse ) {
if ( ( ! collapse ) == collapseButton ) {
await collapseButton.click();
}
},
};

View File

@ -2,7 +2,7 @@
* External dependencies
*/
const { pressKeyWithModifier } = require( '@wordpress/e2e-test-utils' );
const config = require( 'config' );
const { config } = require( '@woocommerce/e2e-environment' );
/**
* Internal dependencies

View File

@ -103,6 +103,9 @@ class WC_Template_Loader {
/**
* Checks whether a block template with that name exists.
*
* **Note: ** This checks both the `templates` and `block-templates` directories
* as both conventions should be supported.
*
* @since 5.5.0
* @param string $template_name Template to check.
* @return boolean
@ -112,7 +115,31 @@ class WC_Template_Loader {
return false;
}
$has_template = is_readable( get_stylesheet_directory() . '/block-templates/' . $template_name . '.html' );
$has_template = false;
$template_filename = $template_name . '.html';
// Since Gutenberg 12.1.0, the conventions for block templates directories have changed,
// we should check both these possible directories for backwards-compatibility.
$possible_templates_dirs = array( 'templates', 'block-templates' );
// Combine the possible root directory names with either the template directory
// or the stylesheet directory for child themes, getting all possible block templates
// locations combinations.
$filepath = DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template_filename;
$legacy_filepath = DIRECTORY_SEPARATOR . 'block-templates' . DIRECTORY_SEPARATOR . $template_filename;
$possible_paths = array(
get_stylesheet_directory() . $filepath,
get_stylesheet_directory() . $legacy_filepath,
get_template_directory() . $filepath,
get_template_directory() . $legacy_filepath,
);
// Check the first matching one.
foreach ( $possible_paths as $path ) {
if ( is_readable( $path ) ) {
$has_template = true;
break;
}
}
/**
* Filters the value of the result of the block template check.

View File

@ -113,12 +113,10 @@ importers:
'@wordpress/babel-preset-default': 3.0.2
'@wordpress/browserslist-config': ^4.1.0
'@wordpress/deprecated': ^3.2.3
config: 3.3.3
faker: ^5.1.0
dependencies:
'@jest/globals': 26.6.2
'@wordpress/deprecated': 3.2.3
config: 3.3.3
faker: 5.5.3
devDependencies:
'@babel/cli': 7.12.8_@babel+core@7.12.9
@ -218,7 +216,6 @@ importers:
'@wordpress/browserslist-config': ^4.1.0
'@wordpress/deprecated': ^3.2.3
'@wordpress/e2e-test-utils': ^4.16.1
config: 3.3.3
eslint: ^8.1.0
faker: ^5.1.0
fishery: ^1.2.0
@ -226,7 +223,6 @@ importers:
'@automattic/puppeteer-utils': github.com/Automattic/puppeteer-utils/0f3ec50
'@wordpress/deprecated': 3.2.3
'@wordpress/e2e-test-utils': 4.16.1_jest@27.3.1
config: 3.3.3
faker: 5.5.3
fishery: 1.4.0
devDependencies:
@ -7572,6 +7568,7 @@ packages:
engines: {node: '>= 6.0.0'}
dependencies:
json5: 2.2.0
dev: true
/config/3.3.6:
resolution: {integrity: sha512-Hj5916C5HFawjYJat1epbyY2PlAgLpBtDUlr0MxGLgo3p5+7kylyvnRY18PqJHgnNWXcdd0eWDemT7eYWuFgwg==}