rogeliog / jest-runner-mocha

A Mocha runner for Jest
70 stars 12 forks source link

How to resolve paths? #7

Open dpoindexter opened 6 years ago

dpoindexter commented 6 years ago

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.

ivn-cote commented 6 years ago

I have the same issue.

itlgit commented 3 years ago

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.