const webpackShimAlias = require('./webpack.shim').resolveAlias; const webpackAliasToJestModules = ()=>{ const ret = { '\\.svg': '/regression/javascript/__mocks__/svg.js' }; Object.keys(webpackShimAlias).forEach((an)=>{ // eg - sources: ./pgadmin/static/js/ to '^sources/(.*)$': '/pgadmin/static/js/$1' let ap = webpackShimAlias[an].replace(__dirname, ''); if(ap.endsWith('/') || ap.endsWith('\\')) { ret[`^${an}/(.*)$`] = ap + '$1'; return; } ret[`^${an}$`] = ap; }); // Overrides ret['^translations$'] = '/regression/javascript/fake_translations'; ret['^pgadmin.browser.messages$'] = '/regression/javascript/fake_messages'; ret['^pgadmin.browser.endpoints$'] = '/regression/javascript/fake_endpoints'; ret['^pgadmin.browser.translations$'] = '/regression/javascript/fake_translations'; ret['^pgadmin.user_management.current_user$'] = '/regression/javascript/fake_current_user'; ret['^pgadmin.server.supported_servers$'] = '/regression/javascript/fake_supported_servers'; const sources = ret['^sources/(.*)$']; delete ret['^sources/(.*)$']; ret['^sources/pgadmin$'] = '/regression/javascript/fake_pgadmin'; ret['^sources/gettext$'] = '/regression/javascript/fake_gettext'; ret['^sources/(.*)$'] = sources; // Only for tests ret['^pgadmin.schema.dir/(.*)$'] = '/pgadmin/browser/server_groups/servers/databases/schemas/static/js/$1'; ret['^browser/(.*)$'] = '/pgadmin/browser/static/js/$1'; return ret; }; module.exports = { 'roots': ['/pgadmin/', '/regression/javascript'], 'moduleFileExtensions': ['js', 'jsx', 'ts', 'tsx'], 'moduleNameMapper': webpackAliasToJestModules(), 'transform': { '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': 'babel-jest', }, 'setupFilesAfterEnv': [ '/regression/javascript/setup-jest.js', ], 'testMatch': [ '/regression/javascript/**/*{spec,test}.{js,jsx,ts,tsx}' ], 'testEnvironment': 'jsdom', 'transformIgnorePatterns': [ '[/\\\\]node_modules[/\\\\](?!react-dnd|dnd-core|@react-dnd).+\\.(js|jsx|mjs|cjs|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$' ] };