Babel-jest with ES6 modules

I am happy to use node 8.6 with the option of experimental ES6 modules (--experimental-modules) enabled. This allows me to write simple ES2015 code for node without the need for babel.

The problem is that when I try to create several tests with a joke, he does not complain about a syntax error: "Unexpected token import."

The .babelrc configuration is as follows:

{
  "env": {
    "test": {
      "presets": [
        ["env", {
          "targets": {
            "node": "8.6"
          }
        }]
      ]
    }
  }
}

My jest.config.js is as follows:

module.exports = {
  testMatch: ['/tests/**/*.js', '**/?(*.)test.js'],
}

Error:

    /app/tests/integration/controller/data-provider/Credentials/CredentialsList.action.test.js:2
    import { Credentials, AdWordsCredentials } from '../../../../../imports/models/data-provider/Credentials.mjs';
    ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
          at Generator.next (<anonymous>)
          at Promise (<anonymous>)

Matching packages:

  • babel-core @ ^ 6.26.0
  • jest @ ^ 21.2.1
  • babel-jest @ ^ 21.2.0
  • babel-preset-env @ ^ 1.6.0

Any help would be appreciated. Thank:)

UPDATE: I tried calling jest without babel with the following command without any changes: node --experimental-modules node_modules/.bin/jest

+4
1

Jest require, . , node --experimental-modules. , , ES6 . . https://github.com/facebook/jest/issues/4842

0

Source: https://habr.com/ru/post/1687124/


All Articles