'tests with jest don't run after updating babel in react
Had to update babel at some points in my project, react, typescript and next
but now the tests are not read
After settings, a error persisted and if removed babel config, error in github actions
My package
"dependencies": {
"@babel/plugin-transform-modules-commonjs": "7.0.0",
"@babel/preset-react": "^7.16.7",
"@babel/runtime": "^7.17.2",
"@react-google-maps/api": "^2.7.0",
"@testing-library/jest-dom": "^5.15.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/plugin-proposal-class-properties": "7.0.0",
"@babel/plugin-proposal-json-strings": "7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/plugin-syntax-dynamic-import": "7.0.0",
"@babel/plugin-syntax-import-meta": "7.0.0",
"@babel/plugin-transform-runtime": "7.0.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-stage-3": "^7.8.3",
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.15",
"@types/google.maps": "^3.47.2",
"@types/node": "^16.3.1",
"@types/react": "^17.0.14",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"babel-jest": "^27.5.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
}
My babel.config with settings for run project
module.exports = {
presets: [
'next/babel',
['@babel/preset-react', { runtime: 'automatic' }],
'@babel/preset-env',
// '@babel/preset-stage-3',
],
plugins: [
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
[
'@babel/plugin-proposal-class-properties',
{ loose: false },
],
'@babel/plugin-proposal-json-strings',
[
'@babel/plugin-transform-runtime',
{
absoluteRuntime: false,
corejs: false,
helpers: true,
regenerator: true,
version: '7.0.0-beta.0',
},
],
],
};
My jest.config
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
"^.+\\.(js|jsx)$": "babel-jest",
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'node',
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
'<rootDir>/coverage',
'<rootDir>/dist',
],
moduleDirectories: [
'<rootDir>/node_modules',
'<rootDir>/src',
'<rootDir>/pages',
],
moduleNameMapper: {
'@src/(.*)': '<rootDir>/src/$1',
'@pages/(.*)': '<rootDir>/pages/$1',
'@styles/(.*)': '<rootDir>/styles/$1',
'\\.(scss|sass|css)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/assetsTransformer.js',
'\\.(css|less)$': '<rootDir>/assetsTransformer.js',
},
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/features/**/*.{js,jsx,ts,tsx}',
'src/components/**/*.{js,jsx,ts,tsx}',
'src/services/**/*.{js,jsx,ts,tsx}',
'src/utils/**/*.{js,jsx,ts,tsx}',
],
testMatch: [
'<rootDir>/src/**/*.test.{js,jsx,ts,tsx}'
],
transformIgnorePatterns: [
"<rootDir>/node_modules/strip-indent/*.{js,jsx,ts,tsx}"
],
};
This is my error, a loop
I need to help, i dont know
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

