jest-runner-mocha
jest-runner-mocha copied to clipboard
How to resolve paths?
I haven't found a way to resolve paths with the mocha runner. Using this config:
{
"jest": {
"runner": "jest-runner-mocha",
"moduleNameMapper": {
"^src/(.*)": "<rootDir>/src/$1"
},
"testMatch": [
"<rootDir>/tests/**/*.test.js"
]
},
"jest-runner-mocha": {
"cliOptions": {
"compiler": "node_modules/babel-register"
}
}
}
...and a module at <rootDir>/src/add.js
, this test fails with Cannot find module src/add.js
:
import { expect } from 'chai';
import add from 'src/add';
it('should add numbers', () => {
expect(add(3, 3)).to.equal(6);
});
It does succeed when I remove the runner
config option from jest
, so I'm guessing that the mocha runner doesn't have a way to use jest's module resolution settings. I also tried doing NODE_PATH=./src yarn jest
, but that didn't work, either.
Is there a recommended way to configure module paths? This would help a great deal with incremental migration.
I have the same issue.
Still an issue in Jest 27.0.6. Using jest-runner-mocha, I'm trying to alias CSS resources to identity-obj-proxy, but getting same error as others.