jest-runner-mocha icon indicating copy to clipboard operation
jest-runner-mocha copied to clipboard

How to resolve paths?

Open dpoindexter opened this issue 7 years ago • 2 comments

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.

dpoindexter avatar Dec 05 '17 22:12 dpoindexter

I have the same issue.

ivn-cote avatar Dec 21 '17 15:12 ivn-cote

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.

itlgit avatar Aug 17 '21 16:08 itlgit