Import files for tests as easy if they are in the same folder as the tested. give your folder structure
src/
component/
fileTotest.js
__tests__/
component/
fileTotest.test.js
in your fileTotest.test.js
import componentTotest from '$/fileTotest.js';
// Gets compiled to:
import fooHelper from '../../src/fileTotest.js';
// No more unecessarie paths!
npm install babel-plugin-relative-import --save-dev
Add a .babelrc
file and write:
{
"plugins": [
"babel-plugin-reflexive-import"
]
}
You can use a custom root with the testPathFolder
option.
And you can set the off set between your source and test.
{
"plugins": [
["babel-plugin-relative-import", {
"testFolder": "__tests__",
"srcFolder": "src"
}]
]
}
Inspired by the babel-relative-import from Olivier Louvignes.