Toolkit: Fix Cannot use "import statement outside" error in tests (#57071)

This commit is contained in:
Jack Westbrook 2022-10-17 16:31:12 +02:00 committed by GitHub
parent ba6c715708
commit fd0fcffc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -30,6 +30,7 @@ const copyFiles = () => {
'src/config/tsconfig.plugin.local.json',
'src/config/eslint.plugin.js',
'src/config/styles.mock.js',
'src/config/jest.babel.config.js',
'src/config/jest.plugin.config.local.js',
'src/config/matchMedia.js',
'src/config/react-inlinesvg.tsx',

View File

@ -0,0 +1,2 @@
// Transform es modules to prevent `SyntaxError: Cannot use import statement outside a module`
module.exports = { presets: [['@babel/preset-env', { targets: { esmodules: false, node: 'current' } }]] };

View File

@ -83,7 +83,10 @@ export const jestConfig = (baseDir: string = process.cwd()) => {
'<rootDir>/spec/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
],
transform: {
'^.+\\.jsx?$': require.resolve('babel-jest'),
'^.+\\.(js|jsx|mjs)$': [
require.resolve('babel-jest'),
{ configFile: path.resolve(__dirname, './jest.babel.config.js') },
],
'^.+\\.tsx?$': require.resolve('ts-jest'),
},
transformIgnorePatterns: [