2020-08-04 22:55:13 +00:00
|
|
|
/**
|
|
|
|
* External Dependencies
|
|
|
|
*/
|
2021-03-08 20:56:47 +00:00
|
|
|
const { WC_E2E_SCREENSHOTS } = process.env;
|
2020-08-04 22:55:13 +00:00
|
|
|
const path = require( 'path' );
|
|
|
|
const fs = require( 'fs' );
|
2020-04-02 13:41:06 +00:00
|
|
|
|
2020-08-04 22:55:13 +00:00
|
|
|
/**
|
|
|
|
* Internal Dependencies
|
|
|
|
*/
|
2021-11-23 12:56:24 +00:00
|
|
|
const { resolveLocalE2ePath } = require( '../utils' );
|
2020-08-04 22:55:13 +00:00
|
|
|
|
2021-10-28 19:32:31 +00:00
|
|
|
const failureSetup = [];
|
2021-03-08 20:56:47 +00:00
|
|
|
if ( WC_E2E_SCREENSHOTS ) {
|
2021-10-28 19:32:31 +00:00
|
|
|
failureSetup.push(
|
|
|
|
path.resolve( __dirname, '../build/setup/jest.failure.js' )
|
|
|
|
);
|
2021-03-08 20:56:47 +00:00
|
|
|
}
|
2021-10-28 19:32:31 +00:00
|
|
|
const setupFilesAfterEnv = [
|
2020-08-04 22:55:13 +00:00
|
|
|
path.resolve( __dirname, '../build/setup/jest.setup.js' ),
|
2021-03-08 20:56:47 +00:00
|
|
|
...failureSetup,
|
2020-08-04 22:55:13 +00:00
|
|
|
'expect-puppeteer',
|
|
|
|
];
|
|
|
|
|
2021-11-23 12:56:24 +00:00
|
|
|
const localJestSetupFile = resolveLocalE2ePath( 'config/jest.setup.js' );
|
|
|
|
const moduleNameMap = resolveLocalE2ePath( '$1' );
|
|
|
|
const testSpecs = resolveLocalE2ePath( 'specs' );
|
|
|
|
|
2021-10-28 19:32:31 +00:00
|
|
|
if ( fs.existsSync( localJestSetupFile ) ) {
|
2020-08-04 22:55:13 +00:00
|
|
|
setupFilesAfterEnv.push( localJestSetupFile );
|
|
|
|
}
|
2020-10-01 18:56:02 +00:00
|
|
|
|
2021-10-28 19:32:31 +00:00
|
|
|
const combinedConfig = {
|
2021-11-23 17:55:42 +00:00
|
|
|
preset: 'jest-puppeteer',
|
|
|
|
clearMocks: true,
|
|
|
|
moduleFileExtensions: [ 'js' ],
|
|
|
|
testMatch: [
|
|
|
|
'**/*.(test|spec).js',
|
|
|
|
'*.(test|spec).js'
|
|
|
|
],
|
2020-04-02 13:41:06 +00:00
|
|
|
moduleNameMapper: {
|
2021-11-23 12:56:24 +00:00
|
|
|
'@woocommerce/e2e/tests/(.*)': moduleNameMap,
|
2020-04-02 13:41:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setupFiles: [ '<rootDir>/config/env.setup.js' ],
|
|
|
|
// A list of paths to modules that run some code to configure or set up the testing framework
|
|
|
|
// before each test
|
2020-08-04 22:55:13 +00:00
|
|
|
setupFilesAfterEnv,
|
2020-04-02 13:41:06 +00:00
|
|
|
|
|
|
|
// Sort test path alphabetically. This is needed so that `activate-and-setup` tests run first
|
|
|
|
testSequencer: '<rootDir>/config/jest-custom-sequencer.js',
|
2020-05-05 16:56:00 +00:00
|
|
|
// Set the test timeout in milliseconds.
|
|
|
|
testTimeout: parseInt( global.process.env.jest_test_timeout ),
|
2020-04-02 13:41:06 +00:00
|
|
|
|
2020-07-28 19:23:32 +00:00
|
|
|
transformIgnorePatterns: [
|
2021-10-28 19:32:31 +00:00
|
|
|
'node_modules/(?!(woocommerce)/)',
|
2020-07-28 19:23:32 +00:00
|
|
|
],
|
2021-11-23 12:56:24 +00:00
|
|
|
roots: [ testSpecs ],
|
2020-04-02 13:41:06 +00:00
|
|
|
};
|
2020-10-01 18:56:02 +00:00
|
|
|
|
|
|
|
if ( process.env.jest_test_spec ) {
|
2021-10-28 19:32:31 +00:00
|
|
|
combinedConfig.testMatch = [ process.env.jest_test_spec ];
|
2020-10-01 18:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = combinedConfig;
|