Description
openedon Oct 9, 2017
Do you want to request a feature or report a bug?
bug
What is the current behavior?
babel-jest is not able to transpile es6 module statements if in *.mjs files
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
What is the expected behavior?
Babel should transpile module import/export statements also with mjs files
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
jest.config.js
module.exports = {
verbose: true,
moduleDirectories: ['node_modules', 'imports'],
testMatch: ['/tests/**/*.js', '**/?(*.)test.js'],
transform: {
'^.+\\.m?js$': 'babel-jest',
},
}
.babelrc
{
"env": {
"test": {
"presets": [
["es2015", { "modules": false }]
],
"plugins": [
["transform-es2015-modules-commonjs", {
"spec": true
}]
]
}
}
}
Note: I've tried disabling the transform-es2015-modules-commonjs plugin, but then the syntax error is back in the test js file
Node: v8.6
babel-core: 6.26.0
babel-jest: 21.2.0
babel-plugin-transform-es2015-modules-commonjs: 6.24.1
babel-preset-es2015: 6.24.1
jest: 21.2.0
Example output error:
yarn run v1.1.0
$ jest
FAIL tests/integration/controller/data-provider/Credentials/CredentialsList.action.test.js
● Test suite failed to run
/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>)
P.S.
If I call my test files ending with .test.mjs
and I edit the testMatch
accordingly, jest won't recognize them