Jest: only supported when running Babel asynchronously

50 Views Asked by At

It seems to be something wrong in my configuration but I'm not able to find what is my problem.

When I try to run a test with this command:

npx jest ./__tests__/ddbb.test.js

I receive this error:

 FAIL  __tests__/ddbb.test.js
  ● Test suite failed to run

    You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.
        at /home/josecarlos/Workspace/nodejs/basketmetrics4/server/babel.config.js

      at loadPartialConfigSync (node_modules/@babel/core/src/config/index.ts:49:60)
      at loadPartialConfigSync (node_modules/@babel/core/src/config/index.ts:68:14)
      at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:228:41)
      at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:289:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:525:32)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)

My configuration files are:

package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "Backend server for basketmetrics",
  "main": "index.js",
  "scripts": {
    "clean-build": "rm -rf ./build",
    "_comment3": "Script para generar el código de servidor de producción",
    "build:test": "webpack --mode production",
    "start:test": "NODE_ENV=test nodemon --experimental-specifier-resolution=node server/index.mjs",
    "start:prod": "NODE_ENV=production node --experimental-specifier-resolution=node server/index.mjs",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.3.1",
    "express": "^4.18.2",
    "helmet": "^7.1.0",
    "morgan": "^1.10.0",
    "mysql2": "^3.6.5"
  },
  "devDependencies": {
    "@babel/cli": "^7.23.4",
    "@babel/core": "^7.23.6",
    "@babel/preset-env": "^7.23.6",
    "@babel/register": "^7.22.15",
    "babel-jest": "^29.7.0",
    "cross-env": "^7.0.3",
    "jest": "^29.7.0",
    "nodemon": "^3.0.1",
    "webpack": "^5.89.0",
    "webpack-cli": "^5.1.4"
  }, 
  "type": "module"
}

jest.config.cjs

module.exports = {
    moduleFileExtensions: ["js", "mjs"],
    transform: {
      "^.+\\.jsx?$": "babel-jest",
    },
  };
  

babel.config.js

module.exports = {
  presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};

What am I doing wrong?

0

There are 0 best solutions below