Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to resolve paths? #7

Open
dpoindexter opened this issue Dec 5, 2017 · 2 comments
Open

How to resolve paths? #7

dpoindexter opened this issue Dec 5, 2017 · 2 comments

Comments

@dpoindexter
Copy link

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
Copy link

I have the same issue.

@itlgit
Copy link

itlgit commented Aug 17, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants