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

Fix mocking assets with special characters in the file path #584

Merged
merged 1 commit into from
Sep 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = (resolve, rootDir) => {
const config = {
moduleFileExtensions: ['jsx', 'js', 'json'],
moduleNameMapper: {
'^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
'^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js')
'^.+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to ignore everything before the end, you can just omit ^.+ altogether and just write \\.css$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. However, turns out the files don't get stubbed, if I change this to \\.css$. This looks like a possible bug in Jest to me (unless it's only supposed to work with regexes that match the whole path). When given a non-anchored regex, this line doesn't replace the module name correctly.

I suggest that we merge this PR as-is, with the anchored regex, and we can open an issue in Jest about regexes like \\.css$ not working correctly.

'^.+\\.css$': resolve('config/jest/CSSStub.js')
},
scriptPreprocessor: resolve('config/jest/transform.js'),
setupFiles: setupFiles,
Expand Down