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

Disabling automock breaks detection of file extension when using moduleNameMapper #1320

Closed
codeheroics opened this issue Jul 26, 2016 · 5 comments

Comments

@codeheroics
Copy link

Hi,

I'm trying to setup with jest 13.2.3 on my current project. We use the webpack alias feature to get simpler module paths (eg. import en from 'i18n/en'; instead of import en from '../../../../i18n/en'), so I've followed this tutorial to setup the package.json for jest, using moduleNameMapper to setup this kind of rule:

{
    "moduleNameMapper": {
      "^i18n": "<rootDir>/src/i18n"
    }
}

Which worked correctly in my test file:

import en from 'i18n/en';
console.log(en); // logs the exported contents of en.js

However, when I tried to disable automock, either via setting automock: true in the package.json or using jest.disableAutomock(), I run into this file not found error:
Error: ENOENT: no such file or directory, stat '/home/codeheroics/dev/front/src/i18n/en'

Am I misunderstanding something in my moduleNameMapper setup, or is there a need to activate automock to get correct file extension detection when using it ?
(I'm overwriting moduleFileExtensions to handle .jsx files, but this problem exists with .js files whether or not it is overwritten)

@cpojer
Copy link
Member

cpojer commented Jul 27, 2016

As a workaround, can you use moduleDirectories instead?

@codeheroics
Copy link
Author

Using moduleDirectories works perfectly as a workaround, thanks!

@cpojer
Copy link
Member

cpojer commented Jul 28, 2016

Ok, I think that's the right solution here actually.

@cpojer cpojer closed this as completed Jul 28, 2016
@codeheroics
Copy link
Author

Isn't it weird that setting or not automock changes the file loading abilities? (and it still feels problematic as moduleNameMapper is the recommended way, in tutorial, to handle webpack aliases, so others could run in the issue)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants