/** * Jest Configuration for Templately React Unit Tests * * Uses @wordpress/jest-preset-default (bundled with @wordpress/scripts) * which provides jsdom environment, babel-jest transform, and WordPress mocks. */ module.exports = { preset: '@wordpress/jest-preset-default', roots: [ '/react-src' ], testMatch: [ '/react-src/**/__tests__/**/*.[jt]s?(x)', '/react-src/**/*.test.[jt]s?(x)', ], testPathIgnorePatterns: [ '/node_modules/', '/vendor/', '/tests/e2e/', ], moduleNameMapper: { // Static asset mocks (must come BEFORE aliases that resolve to asset files) '\\.(jpg|jpeg|png|gif|svg|webp)$': '/tests/js/__mocks__/fileMock.js', // Webpack aliases - icons are React components (iconMock), assets are images (fileMock). // Note: image file extensions above catch ~templately-icons/*.png before this pattern. '^~templately-icons$': '/tests/js/__mocks__/iconMock.js', '^~templately-icons/(.*)$': '/tests/js/__mocks__/iconMock.js', '^~templately-assets$': '/tests/js/__mocks__/fileMock.js', '^~templately-assets/(.*)$': '/tests/js/__mocks__/fileMock.js', '^~templately-hooks/(.*)$': '/react-src/app/hooks/$1', '^~templately-hooks$': '/react-src/app/hooks/index.js', '^~templately-utils/(.*)$': '/react-src/utils/$1', '^~templately-utils$': '/react-src/utils/index.js', '^~templately-redux/(.*)$': '/react-src/redux/$1', '^~templately-redux$': '/react-src/redux/index.js', // lodash-es -> lodash (ESM -> CJS for Jest) '^lodash-es$': 'lodash', '^lodash-es/(.*)$': 'lodash/$1', }, setupFiles: [ '/tests/js/setup-globals.js' ], // @wordpress/jest-preset-default only sets up @wordpress/jest-console. // Extend with jest-dom matchers (toBeInTheDocument, toHaveClass, etc.). setupFilesAfterEnv: [ '@testing-library/jest-dom' ], // Transform all node_modules through babel. Slower but avoids ESM whack-a-mole. // The deep import chains (redux -> store -> components -> block-editor -> css-tree etc.) // pull in many ESM-only packages that Jest cannot handle natively. transformIgnorePatterns: [], };