* convert eslint config to use @woocommerce/eslint-plugin

- removes unnecessary dependencies
- adds e2e-tests/specs to eslint ignore (they are automatically generated)
- turns off rules that will be handled in subsequent pulls (to avoid a mammoth changeset for review).
- NOTE: prettier config needs left in because of a bug with the existing version of `@wordpress/eslint-plugin` pulled in (fixed in https://github.com/WordPress/gutenberg/pull/25068) so I left the file for now.

* prettier fixes.

* remove obsolete plugin and fixes for eslint update

This branch brings an update to eslint which also changes some syntax with plugins. So this commit:

- fixes featuer-flag plugin syntax.
- removed obsolete dependency-group plugin (which is now in the `@woocommerce/eslint-plugin` configuration.

* add to-do comment

* fixes for test runs

- this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run.

* fixes for test runs

- this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run.

* include prettier alias as a dependency

This has to be done because prettier is installed with storybook and thus the alias setup in `@wordpress/scripts` is over-ridden by the storybook import.

* another attempt at e2e-test-fix

* add some debugging and temporarily just add one e2e config test for travis

* more debugging

* try installing full puppeteer and see if fixes

* fix package-lock?

* setupSettings separately from other fixture loading

* add debugging of files

* add another console.log (hopefully trigger travis)

* split out blockPage creation to it’s own as well

* fixed! remove debugging and re-enable travis configs for entire test suite

* fix config and rename e2e-tests to e2e

- fixes the failing product-search test
- tests/e2e-tests was redundant, I changed to `tests/e2e` (this follows a file pattern change made in woocommerce core as well).

* add todo for some eslint properties

* remove unnecessary early function execution

* revert earlier commit and remove duplicate call to createBlockPages
This commit is contained in:
Darren Ethier 2020-09-07 13:31:10 -04:00 committed by GitHub
parent a9bcdb7d08
commit 69ba8161b6
75 changed files with 8362 additions and 12571 deletions

View File

@ -6,3 +6,4 @@ languages
node_modules
vendor
legacy
tests/e2e/specs

View File

@ -1,31 +1,59 @@
module.exports = {
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
'prettier',
'plugin:jest/recommended',
'plugin:react-hooks/recommended',
],
env: {
'jest/globals': true,
},
extends: [ 'plugin:@woocommerce/eslint-plugin/recommended' ],
globals: {
wcSettings: 'readonly',
wcStoreApiNonce: 'readonly',
page: true,
browser: true,
context: true,
jestPuppeteer: true,
fetchMock: true,
jQuery: 'readonly',
IntersectionObserver: 'readonly',
// @todo Move E2E related ESLint configuration into custom config.
//
// We should have linting properties only included for files that they
// are specific to as opposed to globally.
page: 'readonly',
browser: 'readonly',
context: 'readonly',
jestPuppeteer: 'readonly',
},
plugins: [ 'jest', 'woocommerce' ],
rules: {
'@wordpress/dependency-group': 'off',
'woocommerce/dependency-group': 'error',
'woocommerce/feature-flag': 'off',
'valid-jsdoc': 'off',
radix: 'error',
yoda: [ 'error', 'never' ],
// @todo Remove temporary disabling of various eslint rules.
// To keep pull request reviews smaller and changes more precise, new rules
// added via the adoption of `@woocommerce/eslint-plugin` that are failing
// will be handled in individual pulls. The following rules need to be turned
// back on (via individual pulls):
// - jsdoc/require-param
// - jsdoc/check-tag-names
// - jsdoc/check-param-names
// - jsdoc/require-property-description
// - jsdoc/valid-types
// - jsdoc/require-property
// - jsdoc/no-undefined-types
// - jsdoc/check-types
// - jsdoc/require-returns-description
// - jsdoc/require-param-type
// - jsdoc/require-returns-type
// - jsdoc/newline-after-description
// - @wordpress/i18n-translator-comments
// - @wordpress/valid-sprintf
// - @worpdress/no-unused-vars-before-return
// - testing-library/no-await-sync-query
// - @woocommerce/dependency-group
'jsdoc/require-param': 'off',
'jsdoc/check-tag-names': 'off',
'jsdoc/check-param-names': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/valid-types': 'off',
'jsdoc/require-property': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/check-types': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/newline-after-description': 'off',
'@wordpress/i18n-translator-comments': 'off',
'@wordpress/valid-sprintf': 'off',
'@wordpress/no-unused-vars-before-return': 'off',
'testing-library/no-await-sync-query': 'off',
'@woocommerce/dependency-group': 'off',
},
};

View File

@ -1,6 +1,3 @@
{
"labelsToOmit": [
"skip-changelog",
"type: build"
]
"labelsToOmit": [ "skip-changelog", "type: build" ]
}

View File

@ -23,7 +23,7 @@ export default withProductSelector( {
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
"Choose a product to display its add to cart button.",
'Choose a product to display its add to cart button.',
'woo-gutenberg-products-block'
),
} )( Edit );

View File

@ -123,7 +123,7 @@ const Price = isFeaturePluginBuild()
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
"Choose a product to display its price.",
'Choose a product to display its price.',
'woo-gutenberg-products-block'
),
} ),

View File

@ -17,7 +17,7 @@ export default withProductSelector( {
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
"Choose a product to display its rating.",
'Choose a product to display its rating.',
'woo-gutenberg-products-block'
),
} )( Edit );

View File

@ -18,7 +18,7 @@ export default withProductSelector( {
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
"Choose a product to display its sale-badge.",
'Choose a product to display its sale-badge.',
'woo-gutenberg-products-block'
),
} )( Edit );

View File

@ -18,7 +18,7 @@ export default withProductSelector( {
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
"Choose a product to display its short description.",
'Choose a product to display its short description.',
'woo-gutenberg-products-block'
),
} )( Edit );

View File

@ -6,7 +6,9 @@
* @return {boolean} True if a rate exists.
*/
const hasShippingRate = ( shippingRatePackages ) => {
return shippingRatePackages.some( shippingRatePackage => shippingRatePackage.shipping_rates.length );
return shippingRatePackages.some(
( shippingRatePackage ) => shippingRatePackage.shipping_rates.length
);
};
export default hasShippingRate;

View File

@ -5,23 +5,23 @@ import { constrainRangeSliderValues } from '../constrain-range-slider-values';
describe( 'constrainRangeSliderValues', () => {
test.each`
values | min | max | step | isMin | expected
${[ 20, 60 ]} | ${0} | ${70} | ${10} | ${true} | ${[ 20, 60 ]}
${[ 20, 60 ]} | ${20} | ${60} | ${10} | ${true} | ${[ 20, 60 ]}
${[ 20, 60 ]} | ${30} | ${50} | ${10} | ${true} | ${[ 30, 50 ]}
${[ 50, 50 ]} | ${20} | ${60} | ${10} | ${true} | ${[ 50, 60 ]}
${[ 50, 50 ]} | ${20} | ${60} | ${10} | ${false} | ${[ 40, 50 ]}
${[ 20, 60 ]} | ${null} | ${null} | ${10} | ${true} | ${[ 20, 60 ]}
${[ null, null ]} | ${20} | ${60} | ${10} | ${true} | ${[ 20, 60 ]}
${[ '20', '60' ]} | ${30} | ${50} | ${10} | ${true} | ${[ 30, 50 ]}
${[ -60, -20 ]} | ${-70} | ${0} | ${10} | ${true} | ${[ -60, -20 ]}
${[ -60, -20 ]} | ${-60} | ${-20} | ${10} | ${true} | ${[ -60, -20 ]}
${[ -60, -20 ]} | ${-50} | ${-30} | ${10} | ${true} | ${[ -50, -30 ]}
${[ -50, -50 ]} | ${-60} | ${-20} | ${10} | ${true} | ${[ -50, -40 ]}
${[ -50, -50 ]} | ${-60} | ${-20} | ${10} | ${false} | ${[ -60, -50 ]}
${[ -60, -20 ]} | ${null} | ${null} | ${10} | ${true} | ${[ -60, -20 ]}
${[ null, null ]} | ${-60} | ${-20} | ${10} | ${true} | ${[ -60, -20 ]}
${[ '-60', '-20' ]} | ${-50} | ${-30} | ${10} | ${true} | ${[ -50, -30 ]}
values | min | max | step | isMin | expected
${ [ 20, 60 ] } | ${ 0 } | ${ 70 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ 20, 60 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ 20, 60 ] } | ${ 30 } | ${ 50 } | ${ 10 } | ${ true } | ${ [ 30, 50 ] }
${ [ 50, 50 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 50, 60 ] }
${ [ 50, 50 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ false } | ${ [ 40, 50 ] }
${ [ 20, 60 ] } | ${ null } | ${ null } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ null, null ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ '20', '60' ] } | ${ 30 } | ${ 50 } | ${ 10 } | ${ true } | ${ [ 30, 50 ] }
${ [ -60, -20 ] } | ${ -70 } | ${ 0 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ -60, -20 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ -60, -20 ] } | ${ -50 } | ${ -30 } | ${ 10 } | ${ true } | ${ [ -50, -30 ] }
${ [ -50, -50 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -50, -40 ] }
${ [ -50, -50 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ false } | ${ [ -60, -50 ] }
${ [ -60, -20 ] } | ${ null } | ${ null } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ null, null ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ '-60', '-20' ] } | ${ -50 } | ${ -30 } | ${ 10 } | ${ true } | ${ [ -50, -30 ] }
`(
`correctly sets prices to its constraints with arguments values: $values, min: $min, max: $max, step: $step and isMin: $isMin`,
( { values, min, max, step, isMin, expected } ) => {

View File

@ -80,7 +80,7 @@ const FormSubmit = () => {
triggerFetch.setNonce( fetchResponse.headers );
// Handle response.
fetchResponse.json().then( function( response ) {
fetchResponse.json().then( function ( response ) {
if ( ! fetchResponse.ok ) {
// We received an error response.
if ( response.body && response.body.message ) {
@ -111,7 +111,7 @@ const FormSubmit = () => {
} );
} )
.catch( ( error ) => {
error.json().then( function( response ) {
error.json().then( function ( response ) {
// If updated cart state was returned, also update that.
if ( response.data?.cart ) {
receiveCart( response.data.cart );

View File

@ -212,7 +212,7 @@ const CheckoutProcessor = () => {
triggerFetch.setNonce( fetchResponse.headers );
// Handle response.
fetchResponse.json().then( function( response ) {
fetchResponse.json().then( function ( response ) {
if ( ! fetchResponse.ok ) {
// We received an error response.
if ( response.body && response.body.message ) {
@ -237,7 +237,7 @@ const CheckoutProcessor = () => {
} );
} )
.catch( ( error ) => {
error.json().then( function( response ) {
error.json().then( function ( response ) {
// If updated cart state was returned, also update that.
if ( response.data?.cart ) {
receiveCart( response.data.cart );

View File

@ -55,7 +55,7 @@ export const ContainerWidthContextProvider = ( {
{ children }
</div>
</ContainerWidthContext.Provider>
);
);
};
ContainerWidthContextProvider.propTypes = {

View File

@ -16,12 +16,12 @@ describe( 'assertValidContextValue', () => {
},
};
it.each`
testValue | expectedMessage | expectError
${{}} | ${'expected'} | ${true}
${10} | ${'expected'} | ${true}
${{ amountKetchup: 20 }} | ${'not expected'} | ${false}
${{ amountKetchup: '10' }} | ${'expected'} | ${true}
${{ cheeseburger: 'fries', amountKetchup: 20 }} | ${'not expected'} | ${false}
testValue | expectedMessage | expectError
${ {} } | ${ 'expected' } | ${ true }
${ 10 } | ${ 'expected' } | ${ true }
${ { amountKetchup: 20 } } | ${ 'not expected' } | ${ false }
${ { amountKetchup: '10' } } | ${ 'expected' } | ${ true }
${ { cheeseburger: 'fries', amountKetchup: 20 } } | ${ 'not expected' } | ${ false }
`(
'The value of $testValue is $expectedMessage to trigger an Error',
( { testValue, expectError } ) => {

View File

@ -53,11 +53,11 @@ describe( 'usePositionRelativeToViewport', () => {
} );
it.each`
position | isIntersecting | top
${'visible'} | ${true} | ${0}
${'below'} | ${false} | ${10}
${'above'} | ${false} | ${0}
${'above'} | ${false} | ${-10}
position | isIntersecting | top
${ 'visible' } | ${ true } | ${ 0 }
${ 'below' } | ${ false } | ${ 10 }
${ 'above' } | ${ false } | ${ 0 }
${ 'above' } | ${ false } | ${ -10 }
`(
"position relative to viewport is '$position' with isIntersecting=$isIntersecting and top=$top",
( { position, isIntersecting, top } ) => {

View File

@ -16,18 +16,18 @@ describe( 'useShallowEqual', () => {
let renderer;
beforeEach( () => ( renderer = null ) );
it.each`
testValueA | aType | testValueB | bType | expectEqual
${{ a: 'b', foo: 'bar' }} | ${'object'} | ${{ foo: 'bar', a: 'b' }} | ${'object'} | ${true}
${{ a: 'b', foo: 'bar' }} | ${'object'} | ${{ foo: 'bar', a: 'c' }} | ${'object'} | ${false}
${[ 'b', 'bar' ]} | ${'array'} | ${[ 'b', 'bar' ]} | ${'array'} | ${true}
${[ 'b', 'bar' ]} | ${'array'} | ${[ 'bar', 'b' ]} | ${'array'} | ${false}
${1} | ${'number'} | ${1} | ${'number'} | ${true}
${1} | ${'number'} | ${'1'} | ${'string'} | ${false}
${'1'} | ${'string'} | ${'1'} | ${'string'} | ${true}
${1} | ${'number'} | ${2} | ${'number'} | ${false}
${1} | ${'number'} | ${true} | ${'bool'} | ${false}
${0} | ${'number'} | ${false} | ${'bool'} | ${false}
${true} | ${'bool'} | ${true} | ${'bool'} | ${true}
testValueA | aType | testValueB | bType | expectEqual
${ { a: 'b', foo: 'bar' } } | ${ 'object' } | ${ { foo: 'bar', a: 'b' } } | ${ 'object' } | ${ true }
${ { a: 'b', foo: 'bar' } } | ${ 'object' } | ${ { foo: 'bar', a: 'c' } } | ${ 'object' } | ${ false }
${ [ 'b', 'bar' ] } | ${ 'array' } | ${ [ 'b', 'bar' ] } | ${ 'array' } | ${ true }
${ [ 'b', 'bar' ] } | ${ 'array' } | ${ [ 'bar', 'b' ] } | ${ 'array' } | ${ false }
${ 1 } | ${ 'number' } | ${ 1 } | ${ 'number' } | ${ true }
${ 1 } | ${ 'number' } | ${ '1' } | ${ 'string' } | ${ false }
${ '1' } | ${ 'string' } | ${ '1' } | ${ 'string' } | ${ true }
${ 1 } | ${ 'number' } | ${ 2 } | ${ 'number' } | ${ false }
${ 1 } | ${ 'number' } | ${ true } | ${ 'bool' } | ${ false }
${ 0 } | ${ 'number' } | ${ false } | ${ 'bool' } | ${ false }
${ true } | ${ 'bool' } | ${ true } | ${ 'bool' } | ${ true }
`(
'$testValueA ($aType) and $testValueB ($bType) are expected to be equal ($expectEqual)',
( { testValueA, testValueB, expectEqual } ) => {

View File

@ -13,7 +13,7 @@ export const getShippingRatesPackageCount = ( shippingRates ) => {
* @param {Array} shippingRates Shipping rates and packages array.
*/
export const getShippingRatesRateCount = ( shippingRates ) => {
return shippingRates.reduce( function( count, shippingPackage ) {
return shippingRates.reduce( function ( count, shippingPackage ) {
return count + shippingPackage.shipping_rates.length;
}, 0 );
};

View File

@ -5,15 +5,15 @@ import { formatPrice, getCurrency } from '../price';
describe( 'formatPrice', () => {
test.each`
value | prefix | suffix | expected
${1000} | ${'€'} | ${''} | ${'€10'}
${1000} | ${''} | ${'€'} | ${'10€'}
${1000} | ${''} | ${'$'} | ${'10$'}
${'1000'} | ${'€'} | ${''} | ${'€10'}
${0} | ${'€'} | ${''} | ${'€0'}
${''} | ${'€'} | ${''} | ${''}
${null} | ${'€'} | ${''} | ${''}
${undefined} | ${'€'} | ${''} | ${''}
value | prefix | suffix | expected
${ 1000 } | ${ '€' } | ${ '' } | ${ '€10' }
${ 1000 } | ${ '' } | ${ '€' } | ${ '10€' }
${ 1000 } | ${ '' } | ${ '$' } | ${ '10$' }
${ '1000' } | ${ '€' } | ${ '' } | ${ '€10' }
${ 0 } | ${ '€' } | ${ '' } | ${ '€0' }
${ '' } | ${ '€' } | ${ '' } | ${ '' }
${ null } | ${ '€' } | ${ '' } | ${ '' }
${ undefined } | ${ '€' } | ${ '' } | ${ '' }
`(
'correctly formats price given "$value", "$prefix" prefix, and "$suffix" suffix',
( { value, prefix, suffix, expected } ) => {

View File

@ -24,7 +24,7 @@ import { Icon, bill, external } from '@woocommerce/icons';
import Block from './block.js';
import './editor.scss';
export default function( { attributes, setAttributes } ) {
export default function ( { attributes, setAttributes } ) {
const {
className,
heading,

View File

@ -22,7 +22,9 @@ describe( 'usePriceConstraints', () => {
};
it( 'max price constraint should be updated when new price is set', () => {
const renderer = TestRenderer.create( <TestComponent price={ 1000 } /> );
const renderer = TestRenderer.create(
<TestComponent price={ 1000 } />
);
const container = renderer.root.findByType( 'div' );
expect( container.props.maxPriceConstraint ).toBe( 1000 );
@ -33,7 +35,9 @@ describe( 'usePriceConstraints', () => {
} );
it( 'min price constraint should be updated when new price is set', () => {
const renderer = TestRenderer.create( <TestComponent price={ 1000 } /> );
const renderer = TestRenderer.create(
<TestComponent price={ 1000 } />
);
const container = renderer.root.findByType( 'div' );
expect( container.props.minPriceConstraint ).toBe( 1000 );
@ -70,9 +74,7 @@ describe( 'usePriceConstraints', () => {
} );
it( 'min price constraint should be lower if the price is decimal', () => {
const renderer = TestRenderer.create(
<TestComponent price={ 999 } />
);
const renderer = TestRenderer.create( <TestComponent price={ 999 } /> );
const container = renderer.root.findByType( 'div' );
expect( container.props.minPriceConstraint ).toBe( 0 );

View File

@ -63,10 +63,10 @@ describe( 'getCollection', () => {
} );
describe( 'returns expected values for items existing in state', () => {
test.each`
resourceName | ids | query | expected
${'products'} | ${[]} | ${{ someQuery: 2 }} | ${[ 'foo' ]}
${'products/attributes'} | ${[ 10 ]} | ${{ someQuery: 2 }} | ${[ 'bar' ]}
${'products/attributes/terms'} | ${[ 10, 20 ]} | ${{ someQuery: 10 }} | ${[ 42 ]}
resourceName | ids | query | expected
${ 'products' } | ${ [] } | ${ { someQuery: 2 } } | ${ [ 'foo' ] }
${ 'products/attributes' } | ${ [ 10 ] } | ${ { someQuery: 2 } } | ${ [ 'bar' ] }
${ 'products/attributes/terms' } | ${ [ 10, 20 ] } | ${ { someQuery: 10 } } | ${ [ 42 ] }
`(
'for "$resourceName", "$ids", and "$query"',
( { resourceName, ids, query, expected } ) => {

View File

@ -33,10 +33,9 @@ import { STORE_KEY } from './constants';
*/
export const getRoute = createRegistrySelector(
( select ) => ( state, namespace, resourceName, ids = [] ) => {
const hasResolved = select( STORE_KEY ).hasFinishedResolution(
'getRoutes',
[ namespace ]
);
const hasResolved = select(
STORE_KEY
).hasFinishedResolution( 'getRoutes', [ namespace ] );
state = state.routes;
let error = '';
if ( ! state[ namespace ] ) {
@ -86,10 +85,9 @@ export const getRoute = createRegistrySelector(
*/
export const getRoutes = createRegistrySelector(
( select ) => ( state, namespace ) => {
const hasResolved = select( STORE_KEY ).hasFinishedResolution(
'getRoutes',
[ namespace ]
);
const hasResolved = select(
STORE_KEY
).hasFinishedResolution( 'getRoutes', [ namespace ] );
const routes = state.routes[ namespace ];
if ( ! routes ) {
if ( hasResolved ) {

View File

@ -62,10 +62,10 @@ describe( 'getRoute', () => {
describe( 'with no throwing of errors if resolution has not finished', () => {
beforeEach( () => mockHasFinishedResolution.mockReturnValue( false ) );
it.each`
description | args
${'is no route for the given namespace'} | ${[ 'invalid' ]}
${'are no routes for the given namespace, but no route for the given resource'} | ${[ 'wc/blocks', 'invalid' ]}
${'are routes for the given namespace and resource name, but no routes for the given ids'} | ${[ 'wc/blocks', 'products/attributes', [ 10 ] ]}
description | args
${ 'is no route for the given namespace' } | ${ [ 'invalid' ] }
${ 'are no routes for the given namespace, but no route for the given resource' } | ${ [ 'wc/blocks', 'invalid' ] }
${ 'are routes for the given namespace and resource name, but no routes for the given ids' } | ${ [ 'wc/blocks', 'products/attributes', [ 10 ] ] }
`( 'does not throw an error if there $description', ( { args } ) => {
expect( invokeTest( ...args ) ).not.toThrowError();
} );

View File

@ -9,12 +9,12 @@ import {
describe( 'extractResourceNameFromRoute', () => {
it.each`
namespace | route | expected
${'wc/blocks'} | ${'wc/blocks/products'} | ${'products'}
${'wc/other'} | ${'wc/blocks/product'} | ${'wc/blocks/product'}
${'wc/blocks'} | ${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)'} | ${'products/attributes'}
${'wc/blocks'} | ${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms'} | ${'products/attributes/terms'}
${'wc/blocks'} | ${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[d]+)'} | ${'products/attributes/terms'}
namespace | route | expected
${ 'wc/blocks' } | ${ 'wc/blocks/products' } | ${ 'products' }
${ 'wc/other' } | ${ 'wc/blocks/product' } | ${ 'wc/blocks/product' }
${ 'wc/blocks' } | ${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)' } | ${ 'products/attributes' }
${ 'wc/blocks' } | ${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms' } | ${ 'products/attributes/terms' }
${ 'wc/blocks' } | ${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[d]+)' } | ${ 'products/attributes/terms' }
`(
'returns "$expected" when namespace is "$namespace" and route is "$route"',
( { namespace, route, expected } ) => {
@ -27,10 +27,10 @@ describe( 'extractResourceNameFromRoute', () => {
describe( 'getRouteIds', () => {
it.each`
route | expected
${'wc/blocks/products'} | ${[]}
${'wc/blocks/products/(?P<id>[\\d]+)'} | ${[ 'id' ]}
${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)'} | ${[ 'attribute_id', 'id' ]}
route | expected
${ 'wc/blocks/products' } | ${ [] }
${ 'wc/blocks/products/(?P<id>[\\d]+)' } | ${ [ 'id' ] }
${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)' } | ${ [ 'attribute_id', 'id' ] }
`(
'returns "$expected" when route is "$route"',
( { route, expected } ) => {
@ -41,12 +41,12 @@ describe( 'getRouteIds', () => {
describe( 'simplifyRouteWithId', () => {
it.each`
route | matchIds | expected
${'wc/blocks/products'} | ${[]} | ${'wc/blocks/products'}
${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)'} | ${[ 'attribute_id' ]} | ${'wc/blocks/products/attributes/{attribute_id}'}
${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms'} | ${[ 'attribute_id' ]} | ${'wc/blocks/products/attributes/{attribute_id}/terms'}
${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)'} | ${[ 'attribute_id', 'id' ]} | ${'wc/blocks/products/attributes/{attribute_id}/terms/{id}'}
${'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)'} | ${[ 'id', 'attribute_id' ]} | ${'wc/blocks/products/attributes/{attribute_id}/terms/{id}'}
route | matchIds | expected
${ 'wc/blocks/products' } | ${ [] } | ${ 'wc/blocks/products' }
${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)' } | ${ [ 'attribute_id' ] } | ${ 'wc/blocks/products/attributes/{attribute_id}' }
${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms' } | ${ [ 'attribute_id' ] } | ${ 'wc/blocks/products/attributes/{attribute_id}/terms' }
${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)' } | ${ [ 'attribute_id', 'id' ] } | ${ 'wc/blocks/products/attributes/{attribute_id}/terms/{id}' }
${ 'wc/blocks/products/attributes/(?P<attribute_id>[\\d]+)/terms/(?P<id>[\\d]+)' } | ${ [ 'id', 'attribute_id' ] } | ${ 'wc/blocks/products/attributes/{attribute_id}/terms/{id}' }
`(
'returns "$expected" when route is "$route" and matchIds is "$matchIds"',
( { route, matchIds, expected } ) => {

View File

@ -74,9 +74,7 @@ class ToggleButtonControl extends Component {
return (
<Button
key={ `${ option.label }-${
option.value
}-${ index }` }
key={ `${ option.label }-${ option.value }-${ index }` }
value={ option.value }
onClick={ this.onClick }
aria-label={ label + ': ' + option.label }

View File

@ -12,7 +12,7 @@ import { cloneElement } from '@wordpress/element';
// as a replacement for the `@wordpress/component/dashicon` component via
// the Webpack NormalModuleReplacementPlugin plugin.
export default function( props ) {
export default function ( props ) {
let Icon;
switch ( props.icon ) {
case 'arrow-down-alt2':

View File

@ -33,7 +33,7 @@ const openIntentModal = ( stripe, paymentDetails, emitResponse ) => {
return stripe[ isSetupIntent ? 'confirmCardSetup' : 'confirmCardPayment' ](
intentSecret
)
.then( function( response ) {
.then( function ( response ) {
if ( response.error ) {
throw response.error;
}
@ -48,7 +48,7 @@ const openIntentModal = ( stripe, paymentDetails, emitResponse ) => {
checkoutResponse.redirectUrl = verificationUrl;
return checkoutResponse;
} )
.catch( function( error ) {
.catch( function ( error ) {
checkoutResponse.type = emitResponse.responseTypes.ERROR;
checkoutResponse.message = error.message;
checkoutResponse.retry = true;

View File

@ -22,4 +22,3 @@ if ( getStripeServerData().allowPaymentRequest ) {
( Config ) => new Config( PaymentRequestPaymentMethod )
);
}

View File

@ -114,18 +114,8 @@ const getBillingData = ( paymentResponse ) => {
const payerEmail = paymentResponse.payerEmail || '';
const payerPhone = paymentResponse.payerPhone || '';
return {
first_name: name
? name
.split( ' ' )
.slice( 0, 1 )
.join( ' ' )
: '',
last_name: name
? name
.split( ' ' )
.slice( 1 )
.join( ' ' )
: '',
first_name: name ? name.split( ' ' ).slice( 0, 1 ).join( ' ' ) : '',
last_name: name ? name.split( ' ' ).slice( 1 ).join( ' ' ) : '',
email: ( source && source.owner.email ) || payerEmail,
phone:
( source && source.owner.phone ) ||

View File

@ -6,14 +6,14 @@ import { compareWithWpVersion, setSetting } from '..';
describe( 'compareWithWpVersion', () => {
let initial = true;
it.each`
version | operator | result
${'5.3-beta1'} | ${'>'} | ${true}
${'5.3'} | ${'='} | ${true}
${'5.3-beta12-235'} | ${'>'} | ${true}
${'5.3-rc1'} | ${'<'} | ${false}
${'5.3-rc12-235'} | ${'>'} | ${true}
${'5.3.1'} | ${'<'} | ${true}
${'5.4-beta1'} | ${'<'} | ${true}
version | operator | result
${ '5.3-beta1' } | ${ '>' } | ${ true }
${ '5.3' } | ${ '=' } | ${ true }
${ '5.3-beta12-235' } | ${ '>' } | ${ true }
${ '5.3-rc1' } | ${ '<' } | ${ false }
${ '5.3-rc12-235' } | ${ '>' } | ${ true }
${ '5.3.1' } | ${ '<' } | ${ true }
${ '5.4-beta1' } | ${ '<' } | ${ true }
`(
'should return $result when $version is the current wpVersion ' +
'and `5.3` is the version compared using `$operator`',

View File

@ -15,7 +15,7 @@ import getShortcode from './get-shortcode';
* @param {*} blockType Block being rendered.
*/
export const deprecatedConvertToShortcode = ( blockType ) => {
return function( props ) {
return function ( props ) {
const { align, contentVisibility } = props.attributes;
const classes = classnames( align ? `align${ align }` : '', {
'is-hidden-title': ! contentVisibility.title,

View File

@ -1,75 +0,0 @@
/**
* External dependencies
*/
import { RuleTester } from 'eslint';
/**
* Internal dependencies
*/
import rule from '../dependency-group';
const ruleTester = new RuleTester( {
parserOptions: {
sourceType: 'module',
ecmaVersion: 6,
},
} );
ruleTester.run( 'dependency-group', rule, {
valid: [
{
code: `
/**
* External dependencies
*/
import { get } from 'lodash';
import classnames from 'classnames';
import { Component } from '@wordpress/element';
import { SearchListControl } from '@woocommerce/components';
import { withProductVariations } from '@woocommerce/block-hocs';
/**
* Internal dependencies
*/
import edit from './edit';
import './style.scss';`,
},
],
invalid: [
{
code: `
/**
* External dependencies
*/
import { get } from 'lodash';
import './style.scss';
import { withProductVariations } from '@woocommerce/block-hocs';
/**
* Internal dependencies
*/
import edit from './edit';
import classnames from 'classnames';
import { Component } from '@wordpress/element';
import { SearchListControl } from '@woocommerce/components';`,
errors: [
{
message:
'Expected preceding "Internal dependencies" comment block',
},
{
message:
'Expected preceding "External dependencies" comment block',
},
{
message:
'Expected preceding "External dependencies" comment block',
},
{
message:
'Expected preceding "External dependencies" comment block',
},
],
},
],
} );

View File

@ -1,179 +0,0 @@
module.exports = {
meta: {
type: 'layout',
schema: [],
},
create( context ) {
const comments = context.getSourceCode().getAllComments();
/**
* Locality classification of an import, "External" or "Internal".
*
* @typedef {string} WCPackageLocality
*/
/**
* Given a desired locality, generates the expected comment node value
* property.
*
* @param {WCPackageLocality} locality Desired package locality.
*
* @return {string} Expected comment node value.
*/
function getCommentValue( locality ) {
return `*\n * ${ locality } dependencies\n `;
}
/**
* Given an import source string, returns the locality classification
* of the import sort.
*
* @param {string} source Import source string.
*
* @return {WCPackageLocality} Package locality.
*/
function getPackageLocality( source ) {
if ( source.startsWith( '.' ) ) {
return 'Internal';
}
return 'External';
}
/**
* Returns true if the given comment node satisfies a desired locality,
* or false otherwise.
*
* @param {espree.Node} node Comment node to check.
* @param {WCPackageLocality} locality Desired package locality.
*
* @return {boolean} Whether comment node satisfies locality.
*/
function isLocalityDependencyBlock( node, locality ) {
const { type, value } = node;
if ( type !== 'Block' ) {
return false;
}
// Tolerances:
// - Normalize `/**` and `/*`
// - Case insensitive "Dependencies" vs. "dependencies"
// - Ending period
// - "Node" dependencies as an alias for External
if ( locality === 'External' ) {
locality = '(External|Node)';
}
const pattern = new RegExp(
`^\\*?\\n \\* ${ locality } dependencies\\.?\\n $`,
'i'
);
return pattern.test( value );
}
/**
* Returns true if the given node occurs prior in code to a reference,
* or false otherwise.
*
* @param {espree.Node} node Node to test being before reference.
* @param {espree.Node} reference Node against which to compare.
*
* @return {boolean} Whether node occurs before reference.
*/
function isBefore( node, reference ) {
return node.start < reference.start;
}
/**
* Tests source comments to determine whether a comment exists which
* satisfies the desired locality. If a match is found and requires no
* updates, the function returns false. Otherwise, it will return true.
*
* @param {espree.Node} node Node to test.
* @param {WCPackageLocality} locality Desired package locality.
*
* @return {boolean} Whether the node is in the correct locality.
*/
function isNodeInLocality( node, locality ) {
const value = getCommentValue( locality );
let comment;
let nextComment;
for ( let i = 0; i < comments.length; i++ ) {
comment = comments[ i ];
nextComment =
i < comments.length - 1 ? comments[ i + 1 ] : null;
if ( nextComment && isBefore( nextComment, node ) ) {
// If it's not the immediately previous comment, continue.
continue;
}
if ( ! isBefore( comment, node ) ) {
// Exhausted options.
break;
}
if ( ! isLocalityDependencyBlock( comment, locality ) ) {
// Not usable (either not an block comment, or not one
// matching a tolerable pattern).
continue;
}
if ( comment.value === value ) {
// No change needed. (OK)
return true;
}
// Found a comment needing correction.
return false;
}
return false;
}
return {
Program( node ) {
// Since we only care to enforce imports which occur at the
// top-level scope, match on Program and test its children,
// rather than matching the import nodes directly.
node.body.forEach( ( child ) => {
let source;
switch ( child.type ) {
case 'ImportDeclaration':
source = child.source.value;
break;
case 'CallExpression':
const { callee, arguments: args } = child;
if (
callee.name === 'require' &&
args.length === 1 &&
args[ 0 ].type === 'Literal' &&
typeof args[ 0 ].value === 'string'
) {
source = args[ 0 ].value;
}
break;
}
if ( ! source ) {
return;
}
const locality = getPackageLocality( source );
if ( isNodeInLocality( child, locality ) ) {
return;
}
context.report( {
node: child,
message: `Expected preceding "${ locality } dependencies" comment block`,
} );
} );
},
};
},
};

View File

@ -199,8 +199,8 @@ function testIsUsedInIfOrTernary( node, context ) {
conditionalParent &&
binaryParent &&
conditionalParent.test &&
conditionalParent.test.start === binaryParent.start &&
conditionalParent.test.end === binaryParent.end
conditionalParent.test.range[ 0 ] === binaryParent.range[ 0 ] &&
conditionalParent.test.range[ 1 ] === binaryParent.range[ 1 ]
) {
return;
}

View File

@ -11,7 +11,7 @@ function RemoveFilesPlugin( filePath = '' ) {
this.filePath = filePath;
}
RemoveFilesPlugin.prototype.apply = function( compiler ) {
RemoveFilesPlugin.prototype.apply = function ( compiler ) {
compiler.hooks.afterEmit.tap( 'afterEmit', () => {
const files = glob.sync( this.filePath );
files.forEach( ( f ) => {

View File

@ -97,8 +97,9 @@ const getCoreConfig = ( options = {} ) => {
// file name
fileName: 'blocks.ini',
// content of the file
content: `woocommerce_blocks_phase = ${ process.env
.WOOCOMMERCE_BLOCKS_PHASE || 3 }`,
content: `woocommerce_blocks_phase = ${
process.env.WOOCOMMERCE_BLOCKS_PHASE || 3
}`,
} ),
],
};

View File

@ -78,7 +78,7 @@ const getAlias = ( options = {} ) => {
),
'@woocommerce/e2e-tests': path.resolve(
__dirname,
'node_modules/woocommerce/tests/e2e-tests'
'node_modules/woocommerce/tests/e2e'
),
};
};

View File

@ -2,7 +2,7 @@
"name": "woocommerce/woocommerce-blocks",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://woocommerce.com/",
"type":"wordpress-plugin",
"type": "wordpress-plugin",
"keywords": [
"gutenberg",
"woocommerce",

File diff suppressed because it is too large Load Diff

View File

@ -51,9 +51,9 @@
"storybook": "start-storybook -c ./storybook -p 6006 --ci",
"storybook:build": "build-storybook -c ./storybook -o ./storybook/dist",
"test": "wp-scripts test-unit-js --config tests/js/jest.config.json",
"test:e2e": "npm run wp-env:config && ./tests/bin/e2e-test-integration.js",
"test:e2e-dev": "npm run wp-env:config && ./tests/bin/e2e-test-integration.js --dev",
"test:e2e:update": "npm run wp-env:config && ./tests/bin/e2e-test-integration.js -- --updateSnapshot",
"test:e2e": "npm run wp-env:config && cross-env NODE_CONFIG_DIR=tests/e2e/config wp-scripts test-e2e --config tests/e2e/config/jest.config.js",
"test:e2e-dev": "npm run wp-env:config && cross-env NODE_CONFIG_DIR=tests/e2e/config wp-scripts test-e2e --config tests/e2e/config/jest.config.js --puppeteer-interactive",
"test:e2e:update": "npm run wp-env:config && cross-env NODE_CONFIG_DIR=tests/e2e/config wp-scripts test-e2e --config tests/e2e/config/jest.config.js --updateSnapshot",
"test:help": "wp-scripts test-unit-js --help",
"test:update": "wp-scripts test-unit-js --updateSnapshot --config tests/js/jest.config.json",
"test:watch": "npm run test -- --watch",
@ -82,6 +82,7 @@
"@types/react": "16.9.46",
"@types/wordpress__data": "4.6.8",
"@types/wordpress__element": "2.4.1",
"@woocommerce/eslint-plugin": "^1.0.0-beta.0",
"@woocommerce/woocommerce-rest-api": "1.0.1",
"@wordpress/babel-preset-default": "4.10.0",
"@wordpress/base-styles": "1.4.0",
@ -94,18 +95,12 @@
"@wordpress/editor": "9.10.0",
"@wordpress/element": "2.10.0",
"@wordpress/env": "1.5.0",
"@wordpress/eslint-plugin": "3.3.0",
"@wordpress/html-entities": "2.5.0",
"@wordpress/i18n": "3.8.0",
"@wordpress/is-shallow-equal": "1.7.0",
"@wordpress/jest-console": "3.6.0",
"@wordpress/jest-preset-default": "5.3.1",
"@wordpress/scripts": "6.2.0",
"@wordpress/scripts": "12.0.0",
"autoprefixer": "9.8.6",
"axios": "0.19.2",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"babel-loader": "8.1.0",
"babel-plugin-transform-async-generator-functions": "6.24.1",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-react-jsx": "6.24.1",
@ -116,43 +111,32 @@
"core-js": "3.6.5",
"create-file-webpack": "1.0.2",
"cross-env": "6.0.3",
"css-loader": "3.6.0",
"cssnano": "4.1.10",
"deep-freeze": "0.0.1",
"eslint": "6.8.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-jest": "23.20.0",
"eslint-plugin-react-hooks": "4.0.0",
"eslint-plugin-woocommerce": "file:bin/eslint-plugin-woocommerce",
"fs-extra": "9.0.1",
"glob": "7.1.6",
"glob-promise": "3.4.0",
"husky": "2.4.1",
"ignore-loader": "0.1.2",
"jest": "25.5.4",
"jest-environment-jsdom-sixteen": "1.0.3",
"jest-fetch-mock": "3.0.3",
"jest-puppeteer": "4.4.0",
"lint-staged": "9.5.0",
"merge-config": "2.0.0",
"mini-css-extract-plugin": "0.10.0",
"node-sass": "4.14.1",
"postcss-loader": "3.0.0",
"prettier": "npm:wp-prettier@1.19.1",
"prettier": "npm:wp-prettier@2.0.5",
"progress-bar-webpack-plugin": "2.1.0",
"promptly": "3.0.3",
"puppeteer": "2.1.1",
"react-test-renderer": "16.13.0",
"request-promise": "4.2.6",
"rimraf": "3.0.2",
"sass-loader": "7.3.1",
"source-map-explorer": "2.5.0",
"stylelint": "12.0.1",
"stylelint-config-wordpress": "13.1.0",
"typescript": "3.9.7",
"webpack": "4.44.1",
"webpack-cli": "3.3.12",
"webpack-rtl-plugin": "2.0.0",
"woocommerce": "git+https://github.com/woocommerce/woocommerce.git#release/4.1",
"woocommerce": "git+https://github.com/woocommerce/woocommerce.git#release/4.4",
"zenhub-api": "0.2.0"
},
"engines": {
@ -173,7 +157,6 @@
"dinero.js": "1.8.1",
"downshift": "4.1.0",
"html-react-parser": "0.13.0",
"jest-environment-jsdom-sixteen": "1.0.3",
"react-number-format": "4.4.1",
"reakit": "1.1.2",
"trim-html": "0.1.9",

View File

@ -6,14 +6,14 @@
"composer": {
"enabled": false
},
"labels": ["type: dependencies", "skip-changelog"],
"labels": [ "type: dependencies", "skip-changelog" ],
"packageRules": [
{
"packageNames": [ "automattic/jetpack-autoloader" ],
"rangeStrategy": "bump"
},
{
"updateTypes": ["minor", "patch", "pin", "digest"],
"updateTypes": [ "minor", "patch", "pin", "digest" ],
"automerge": true
}
]

View File

@ -1,14 +0,0 @@
const Sequencer = require( '@jest/test-sequencer' ).default;
class CustomSequencer extends Sequencer {
sort( tests ) {
// Test structure information
// https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
const copyTests = Array.from( tests );
return copyTests.sort( ( testA, testB ) =>
testA.path > testB.path ? 1 : -1
);
}
}
module.exports = CustomSequencer;

View File

@ -1,36 +0,0 @@
module.exports = {
// Automatically clear mock calls and instances between every test
clearMocks: true,
// An array of file extensions your modules use
moduleFileExtensions: [ 'js' ],
moduleNameMapper: {
'@woocommerce/e2e-tests/(.*)':
'<rootDir>/node_modules/woocommerce/tests/e2e-tests/$1',
'@woocommerce/blocks-test-utils': '<rootDir>/tests/utils',
},
preset: 'jest-puppeteer',
// Where to look for test files
roots: [ '<rootDir>/tests/e2e-tests/specs' ],
globalSetup: '<rootDir>/tests/e2e-tests/config/setup.js',
globalTeardown: '<rootDir>/tests/e2e-tests/config/teardown.js',
setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework
// before each test
setupFilesAfterEnv: [
'<rootDir>/tests/e2e-tests/config/custom-matchers/index.js',
'<rootDir>/tests/e2e-tests/config/jest.setup.js',
'expect-puppeteer',
],
// The glob patterns Jest uses to detect test files
testMatch: [ '**/*.(test|spec).js' ],
// Sort test path alphabetically. This is needed so that `activate-and-setup` tests run first
testSequencer: '<rootDir>/tests/e2e-tests/config/jest-custom-sequencer.js',
transformIgnorePatterns: [ 'node_modules/(?!(woocommerce)/)' ],
};

View File

@ -6,8 +6,9 @@ expect.extend( {
if ( gutenbergNotFoundError !== null ) {
return {
message: () =>
`the ${ block.name ||
'block' } is not registered and not loading in the editor.`,
`the ${
block.name || 'block'
} is not registered and not loading in the editor.`,
pass: false,
};
}
@ -18,8 +19,9 @@ expect.extend( {
if ( gutenbergValidationError !== null ) {
return {
message: () =>
`the ${ block.name ||
'block' } had a validation error while trying to render.`,
`the ${
block.name || 'block'
} had a validation error while trying to render.`,
pass: false,
};
}
@ -30,8 +32,9 @@ expect.extend( {
if ( errorBoundary !== null ) {
return {
message: () =>
`the ${ block.name ||
'block' } had a js error that was caught by our errorBoundary.`,
`the ${
block.name || 'block'
} had a js error that was caught by our errorBoundary.`,
pass: false,
};
}

View File

@ -0,0 +1,30 @@
module.exports = {
...require( '@wordpress/scripts/config/jest-e2e.config' ),
rootDir: '../../../',
// Automatically clear mock calls and instances between every test
clearMocks: true,
// An array of file extensions your modules use
moduleFileExtensions: [ 'js' ],
moduleNameMapper: {
'@woocommerce/e2e-tests/(.*)':
'<rootDir>/node_modules/woocommerce/tests/e2e/$1',
'@woocommerce/blocks-test-utils': '<rootDir>/tests/utils',
},
// Where to look for test files
roots: [ '<rootDir>/tests/e2e/specs' ],
globalSetup: '<rootDir>/tests/e2e/config/setup.js',
globalTeardown: '<rootDir>/tests/e2e/config/teardown.js',
setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework
// before each test
setupFilesAfterEnv: [
'<rootDir>/tests/e2e/config/custom-matchers/index.js',
'<rootDir>/tests/e2e/config/jest.setup.js',
'expect-puppeteer',
],
transformIgnorePatterns: [ 'node_modules/(?!(woocommerce)/)' ],
};

View File

@ -18,7 +18,7 @@ let jestTimeoutInMilliSeconds = 30000;
// Use `await jestPuppeteer.debug()` in test code to pause execution.
if (
process.env.JEST_PUPPETEER_CONFIG ===
'tests/e2e-tests/config/jest-puppeteer.dev.config.js'
'tests/e2e/config/jest-puppeteer.dev.config.js'
) {
jestTimeoutInMilliSeconds = 120000;
}

View File

@ -24,22 +24,25 @@ module.exports = async ( globalConfig ) => {
await setupPuppeteer( globalConfig );
try {
// do setupSettings separately which hopefully gives a chance for WooCommerce
// to be configured before the others are executed.
await setupSettings();
const pages = await createBlockPages();
/**
* Promise.all will return an array of all promises resolved values.
* Some functions like setupSettings and enablePaymentGateways resolve
* to server data so we ignore the values here.
*/
const results = await Promise.all( [
setupSettings(),
createTaxes(),
createCoupons(),
createCategories(),
createShippingZones(),
createBlockPages(),
enablePaymentGateways(),
setupPageSettings(),
] );
const [ , taxes, coupons, categories, shippingZones, pages ] = results;
const [ taxes, coupons, categories, shippingZones ] = results;
// Create products after categories.
const products = await createProducts( categories );

View File

@ -28,7 +28,7 @@
"@woocommerce/blocks-test-utils": "tests/utils"
},
"setupFiles": [
"<rootDir>/node_modules/@wordpress/jest-preset-default/scripts/setup-globals.js",
"@wordpress/jest-preset-default/scripts/setup-globals.js",
"<rootDir>/tests/js/setup-globals.js",
"<rootDir>/tests/js/setup-fetch.js"
],

View File

@ -35,7 +35,7 @@ global.jQuery = () => ( {
off: () => void null,
} );
global.IntersectionObserver = function() {
global.IntersectionObserver = function () {
return {
observe: () => void null,
unobserve: () => void null,

View File

@ -26,13 +26,15 @@
"@woocommerce/base-hocs/*": [ "assets/js/base/hocs/*" ],
"@woocommerce/base-hooks": [ "assets/js/base/hooks" ],
"@woocommerce/base-utils": [ "assets/js/base/utils" ],
"@woocommerce/editor-components/*": [ "assets/js/editor-components/*" ],
"@woocommerce/editor-components/*": [
"assets/js/editor-components/*"
],
"@woocommerce/block-data": [ "assets/js/data" ],
"@woocommerce/block-hocs": [ "assets/js/hocs" ],
"@woocommerce/blocks-registry": [ "assets/js/blocks-registry" ],
"@woocommerce/block-settings": [ "assets/js/settings/blocks" ],
"@woocommerce/e2e-tests": [
"node_modules/woocommerce/tests/e2e-tests"
"node_modules/woocommerce/tests/e2e"
],
"@woocommerce/icons": [ "assets/js/icons" ],
"@woocommerce/resource-previews": [ "assets/js/previews" ],