I'm having trouble integrating unit tests in a particular folder of my project.
My architecture is as follows:
|_ shared
|_ job-board
|_ admin-panel
job_board and admin-panel each contain a symlink pointing to shared, at ./client/src/shared
, and each contain a node_modules
folder with babel-eslint installed. shared does NOT contain a node_modules folder, and relies on the 2 other folder's node_modules.
With this architecture, I've managed to configure all the tools I'm using (Webpack, eslint, eslint-loader, ... but Jest).
The problem is, when I create a *.test.js file in job_board/*
or admin_panel/*
, babel-jest is applied correctly on this file, but when I create this file in shared/*
, babel-jest isn't applied (as babel-jest is not available in shared
), as the following error proves:
FAIL ..\shared\utils\tests\StringUtils.test.js
● Test suite failed to run
SyntaxError: Unexpected token import
Here is my jest-config.json file:
{
"moduleFileExtensions": [
"js"
],
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy"
},
"modulePaths": [
"<rootDir>/client"
],
"testPathDirs": [
"<rootDir>",
"<rootDir>/../shared"
],
"testRegex": "(\\.|/)test\\.jsx?$"
}
(Note that I had to add "<rootDir>/../shared"
to testPathDirs
so that *.test.js files could be found)
And my .babelrc file:
{
"plugins": [
"transform-decorators-legacy",
"transform-object-rest-spread"
],
"presets": [
["es2015", { "modules": false }],
"react",
"stage-0"
],
"env": {
"development": {
"presets": [
"react-hmre"
]
},
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
Finally, I run my tests with: node --harmony_proxies node_modules/jest-cli/bin/jest.js --config ./jest-config.json
Am I missing something out, or is this really a lack of a feature giving the ability to provide a "root" for babel-eslint or something?
I also opened an issue on the Jest repo, but it has been closed. So here I am!
Jest configuration pasted above.
jest-cli: 18.1.0
node: 5.6.0
npm: 3.6.0
OS: Windows 10