2021-07-14 20:38:57 +00:00
/ * *
* External packages
* /
const path = require ( 'path' ) ;
2023-09-06 06:21:09 +00:00
// These modules need to be transformed because they are not transpiled to CommonJS.
const transformModules = [ 'is-plain-obj' , 'memize' ] ;
// Ignore all node_modules except for the ones we need to transform.
const transformIgnorePatterns = [
` node_modules/(?!.pnpm/ ${ transformModules . join (
'|.pnpm/'
) } | $ { transformModules . join ( '|' ) } ) ` ,
'/build/' ,
] ;
2021-07-14 20:38:57 +00:00
module . exports = {
moduleNameMapper : {
tinymce : path . resolve ( _ _dirname , 'build/mocks/tinymce' ) ,
2022-01-06 12:53:30 +00:00
'@woocommerce/settings' : path . resolve (
_ _dirname ,
'build/mocks/woocommerce-settings'
) ,
2023-05-10 12:36:42 +00:00
'@woocommerce/tracks' : path . resolve (
_ _dirname ,
'build/mocks/woocommerce-tracks'
) ,
2022-03-21 10:28:05 +00:00
'~/(.*)' : path . resolve (
_ _dirname ,
'../../../plugins/woocommerce-admin/client/$1'
) ,
2022-08-31 04:06:51 +00:00
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$' :
path . resolve ( _ _dirname , 'build/mocks/static' ) ,
2021-07-14 20:38:57 +00:00
'\\.(scss|css)$' : path . resolve (
_ _dirname ,
'build/mocks/style-mock.js'
) ,
2023-12-05 08:36:30 +00:00
// Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451
"uuid" : require . resolve ( 'uuid' ) ,
2021-07-14 20:38:57 +00:00
} ,
restoreMocks : true ,
setupFiles : [
path . resolve ( _ _dirname , 'build/setup-window-globals.js' ) ,
path . resolve ( _ _dirname , 'build/setup-globals.js' ) ,
] ,
setupFilesAfterEnv : [
path . resolve ( _ _dirname , 'build/setup-react-testing-library.js' ) ,
] ,
testMatch : [
'**/__tests__/**/*.[jt]s?(x)' ,
'**/test/*.[jt]s?(x)' ,
'**/?(*.)test.[jt]s?(x)' ,
] ,
testPathIgnorePatterns : [
'/node_modules/' ,
'<rootDir>/.*/build/' ,
'<rootDir>/.*/build-module/' ,
'<rootDir>/tests/e2e/' ,
] ,
2023-09-06 06:21:09 +00:00
transformIgnorePatterns ,
2021-07-14 20:38:57 +00:00
transform : {
2022-08-31 04:06:51 +00:00
'^.+\\is-plain-obj/index\\.js$' : 'babel-jest' ,
2023-09-06 06:21:09 +00:00
'^.+\\memize/dist/index\\.js$' : 'babel-jest' ,
2021-07-14 20:38:57 +00:00
'^.+\\.[jt]sx?$' : 'ts-jest' ,
} ,
2021-07-29 01:30:22 +00:00
testEnvironment : 'jest-environment-jsdom' ,
2021-07-14 20:38:57 +00:00
timers : 'modern' ,
verbose : true ,
} ;