Kha*_*794 5 node.js reactjs jestjs babel-jest es6-modules
I have a monorepo setup where the project running tests is trying to load a file from outside the current working directory.
Directory structure
root
mainApp
src...
library
greetings.js
Run Code Online (Sandbox Code Playgroud)
Within greetings.js
export const greetings = "hello World!"
Run Code Online (Sandbox Code Playgroud)
Every time I try to import from greetings.js in my mainApp test files
//mainApp.test.js
import {greetings} from "../../greetings.js";
Run Code Online (Sandbox Code Playgroud)
I get error from Jest in console
Jest encountered an unexpected token
SyntaxError: Unexpected token export
Run Code Online (Sandbox Code Playgroud)
One solution in the following url is to add .babelrc to library folder https://github.com/coryhouse/react-slingshot/issues/455
I have quite a few libraries and adding .babelrc to each one isn't that clean. Is there any other / better way of achieving this.
I have even tried to add the following within setUp.js file for jest
require('babel-register')({
plugins: ['transform-es2015-modules-commonjs'],
presets: ['env']
});
Run Code Online (Sandbox Code Playgroud)
But jest is still failing. Any help would be greatly appreciated!!
Many Thanks
| 归档时间: |
|
| 查看次数: |
2055 次 |
| 最近记录: |