woocommerce/packages/js/e2e-environment/config/jest.config.js

69 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
* External Dependencies
*/
2021-03-08 20:56:47 +00:00
const { WC_E2E_SCREENSHOTS } = process.env;
const path = require( 'path' );
const fs = require( 'fs' );
/**
* Internal Dependencies
*/
const { resolveLocalE2ePath } = require( '../utils' );
const failureSetup = [];
2021-03-08 20:56:47 +00:00
if ( WC_E2E_SCREENSHOTS ) {
failureSetup.push(
path.resolve( __dirname, '../build/setup/jest.failure.js' )
);
2021-03-08 20:56:47 +00:00
}
const setupFilesAfterEnv = [
path.resolve( __dirname, '../build/setup/jest.setup.js' ),
2021-03-08 20:56:47 +00:00
...failureSetup,
'expect-puppeteer',
];
const localJestSetupFile = resolveLocalE2ePath( 'config/jest.setup.js' );
const moduleNameMap = resolveLocalE2ePath( '$1' );
const testSpecs = resolveLocalE2ePath( 'specs' );
if ( fs.existsSync( localJestSetupFile ) ) {
setupFilesAfterEnv.push( localJestSetupFile );
}
const combinedConfig = {
preset: 'jest-puppeteer',
clearMocks: true,
moduleFileExtensions: [ 'js' ],
testMatch: [
'**/*.(test|spec).js',
'*.(test|spec).js'
],
moduleNameMapper: {
'@woocommerce/e2e/tests/(.*)': moduleNameMap,
},
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
setupFilesAfterEnv,
// 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-07-28 19:23:32 +00:00
transformIgnorePatterns: [
'node_modules/(?!(woocommerce)/)',
2020-07-28 19:23:32 +00:00
],
2021-12-01 19:35:06 +00:00
testRunner: 'jest-circus/runner',
roots: [ testSpecs ],
};
if ( process.env.jest_test_spec ) {
combinedConfig.testMatch = [ process.env.jest_test_spec ];
}
module.exports = combinedConfig;