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

Add moduleNameMapper ordering note to the documentation #5249

Merged
merged 2 commits into from
Jan 8, 2018

Conversation

emileber
Copy link
Contributor

@emileber emileber commented Jan 8, 2018

Summary

Related to #870 (comment)

Just a note for future readers, the moduleNameMapper ordering is important.

I wanted to stub style imported in modules, something like:

// module.js
import Style from '@/path/to/style.scss';
import App from './App';

So I created a style stub file:

// test/unit/stubs/style.js
module.exports = '.style-stub{color:red;}';

After messing around with the following jest.conf.js:

moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1', // '@' alias
    '^.*\\.scss$': '<rootDir>/test/unit/stubs/style.js',
}

The @ alias rule was resolving before my .scss rule, so the style file was loaded as a normal module and would crash the test.

The solution was to put specific rules first.

moduleNameMapper: {
    '^.*\\.scss$': '<rootDir>/test/unit/stubs/style.js',
    '^@/(.*)$': '<rootDir>/src/$1',
}

@codecov-io
Copy link

codecov-io commented Jan 8, 2018

Codecov Report

Merging #5249 into master will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5249      +/-   ##
==========================================
- Coverage   61.25%   61.18%   -0.08%     
==========================================
  Files         203      202       -1     
  Lines        6786     6771      -15     
  Branches        3        4       +1     
==========================================
- Hits         4157     4143      -14     
+ Misses       2628     2627       -1     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-diff/src/index.js 84.09% <0%> (ø) ⬆️
packages/pretty-format/src/index.js 96.45% <0%> (ø) ⬆️
packages/jest-matcher-utils/src/index.js 100% <0%> (ø) ⬆️
packages/jest-snapshot/src/plugins.js 80% <0%> (ø) ⬆️
...ckages/pretty-format/src/plugins/dom_collection.js

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38aec14...0215ed4. Read the comment docs.

@github-actions
Copy link

This pull request 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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants