2020-06-05 16:49:07 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { setup as setupPuppeteer } from 'jest-environment-puppeteer';
|
2022-04-06 11:22:51 +00:00
|
|
|
const { truncateSync, existsSync } = require( 'fs' );
|
2020-06-05 16:49:07 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
setupSettings,
|
2020-07-29 13:39:15 +00:00
|
|
|
setupPageSettings,
|
2020-06-05 16:49:07 +00:00
|
|
|
createTaxes,
|
|
|
|
createCoupons,
|
|
|
|
createProducts,
|
2020-07-02 10:32:42 +00:00
|
|
|
createReviews,
|
2020-07-06 18:48:39 +00:00
|
|
|
createCategories,
|
2022-02-21 12:26:22 +00:00
|
|
|
createTags,
|
2020-06-05 16:49:07 +00:00
|
|
|
createShippingZones,
|
2020-06-15 14:59:18 +00:00
|
|
|
createBlockPages,
|
2020-06-05 16:49:07 +00:00
|
|
|
enablePaymentGateways,
|
2021-12-23 16:26:10 +00:00
|
|
|
createProductAttributes,
|
2020-06-05 16:49:07 +00:00
|
|
|
} from '../fixtures/fixture-loaders';
|
2022-04-04 12:30:07 +00:00
|
|
|
import { PERFORMANCE_REPORT_FILENAME } from '../../utils/constants';
|
2020-06-05 16:49:07 +00:00
|
|
|
|
|
|
|
module.exports = async ( globalConfig ) => {
|
|
|
|
// we need to load puppeteer global setup here.
|
|
|
|
await setupPuppeteer( globalConfig );
|
|
|
|
|
2020-06-17 20:28:11 +00:00
|
|
|
try {
|
2020-09-07 17:31:10 +00:00
|
|
|
// do setupSettings separately which hopefully gives a chance for WooCommerce
|
|
|
|
// to be configured before the others are executed.
|
|
|
|
await setupSettings();
|
|
|
|
const pages = await createBlockPages();
|
|
|
|
|
2020-06-17 20:28:11 +00:00
|
|
|
/**
|
|
|
|
* 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( [
|
|
|
|
createTaxes(),
|
|
|
|
createCoupons(),
|
2020-07-06 18:48:39 +00:00
|
|
|
createCategories(),
|
2022-02-21 12:26:22 +00:00
|
|
|
createTags(),
|
2020-06-17 20:28:11 +00:00
|
|
|
createShippingZones(),
|
2021-12-23 16:26:10 +00:00
|
|
|
createProductAttributes(),
|
2020-06-17 20:28:11 +00:00
|
|
|
enablePaymentGateways(),
|
2020-07-29 13:39:15 +00:00
|
|
|
setupPageSettings(),
|
2022-02-21 12:26:22 +00:00
|
|
|
] ).catch( console.log );
|
2021-12-23 16:26:10 +00:00
|
|
|
const [
|
|
|
|
taxes,
|
|
|
|
coupons,
|
|
|
|
categories,
|
2022-02-21 12:26:22 +00:00
|
|
|
tags,
|
2021-12-23 16:26:10 +00:00
|
|
|
shippingZones,
|
|
|
|
attributes,
|
|
|
|
] = results;
|
2020-07-06 18:48:39 +00:00
|
|
|
// Create products after categories.
|
2020-07-02 10:32:42 +00:00
|
|
|
|
2022-02-21 12:26:22 +00:00
|
|
|
const products = await createProducts( categories, tags, attributes );
|
2020-07-02 10:32:42 +00:00
|
|
|
/**
|
2020-07-06 18:48:39 +00:00
|
|
|
* Create fixture reviews data for each product.
|
2020-07-02 10:32:42 +00:00
|
|
|
*/
|
2020-07-06 18:48:39 +00:00
|
|
|
products.forEach( async ( productId ) => {
|
|
|
|
await createReviews( productId );
|
|
|
|
} );
|
2020-07-02 10:32:42 +00:00
|
|
|
|
2022-04-04 12:30:07 +00:00
|
|
|
// Wipe the performance e2e file at the start of every run
|
2022-04-06 11:22:51 +00:00
|
|
|
if ( existsSync( PERFORMANCE_REPORT_FILENAME ) ) {
|
|
|
|
truncateSync( PERFORMANCE_REPORT_FILENAME );
|
|
|
|
}
|
2022-04-04 12:30:07 +00:00
|
|
|
|
2020-06-17 20:28:11 +00:00
|
|
|
global.fixtureData = {
|
|
|
|
taxes,
|
|
|
|
coupons,
|
|
|
|
products,
|
|
|
|
shippingZones,
|
|
|
|
pages,
|
2021-12-23 16:26:10 +00:00
|
|
|
attributes,
|
2022-02-21 12:26:22 +00:00
|
|
|
categories,
|
|
|
|
tags,
|
2020-06-17 20:28:11 +00:00
|
|
|
};
|
|
|
|
} catch ( e ) {
|
|
|
|
console.log( e );
|
|
|
|
}
|
2020-06-05 16:49:07 +00:00
|
|
|
};
|