This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
/
setup.js
101 lines (93 loc) · 2.56 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* eslint-disable no-console */
/**
* External dependencies
*/
import path from 'path';
import { setup as setupPuppeteer } from 'jest-environment-puppeteer';
const { truncateSync, existsSync, unlinkSync } = require( 'fs' );
/**
* Internal dependencies
*/
import {
setupSettings,
setupPageSettings,
createTaxes,
createCoupons,
createProducts,
createReviews,
createCategories,
createTags,
createShippingZones,
createBlockPages,
enablePaymentGateways,
createProductAttributes,
disableAttributeLookup,
} from '../fixtures/fixture-loaders';
import { PERFORMANCE_REPORT_FILENAME } from '../../utils/constants';
import { GUTENBERG_EDITOR_CONTEXT } from '../utils';
module.exports = async ( globalConfig ) => {
/**
* We have to remove snapshots to avoid "obsolete snapshot" errors.
*
* @todo Remove this logic when WordPress 6.1 is released.
*/
if ( GUTENBERG_EDITOR_CONTEXT !== 'core' ) {
unlinkSync(
path.join(
__dirname,
'../specs/backend/__snapshots__/site-editing-templates.test.js.snap'
)
);
}
// we need to load puppeteer global setup here.
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( [
createTaxes(),
createCoupons(),
createCategories(),
createTags(),
createShippingZones(),
createProductAttributes(),
enablePaymentGateways(),
setupPageSettings(),
] ).catch( console.log );
const [ taxes, coupons, categories, tags, shippingZones, attributes ] =
results;
// Create products after categories.
const products = await createProducts( categories, tags, attributes );
/**
* Create fixture reviews data for each product.
*/
products.forEach( async ( productId ) => {
await createReviews( productId );
} );
// This is necessary for avoid this bug https://github.com/woocommerce/woocommerce/issues/32065
await disableAttributeLookup();
// Wipe the performance e2e file at the start of every run
if ( existsSync( PERFORMANCE_REPORT_FILENAME ) ) {
truncateSync( PERFORMANCE_REPORT_FILENAME );
}
global.fixtureData = {
taxes,
coupons,
products,
shippingZones,
pages,
attributes,
categories,
tags,
};
} catch ( e ) {
console.log( e );
}
};