Skip to content

Commit

Permalink
Fix for jest handling of static assets when running tests. See:
Browse files Browse the repository at this point in the history
  • Loading branch information
raythree committed Aug 15, 2017
1 parent 57a54e7 commit db99aaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@
"url": "https://github.com/coryhouse/react-slingshot"
},
"jest": {
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy",
"^.+\\.(gif|ttf|eot|svg|woff|woff2|ico)$": "<rootDir>/tools/fileMock.js"
}
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tools/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/tools/assetsTransformer.js"
}
},
"babel": {
"presets": [
Expand Down
14 changes: 14 additions & 0 deletions tools/assetsTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//---------------------------------------------------------------------
// This is a fix for jest handling static assets like imported images
// when running tests. It's configured in jest section of package.json
//
// See:
// https://github.com/facebook/jest/issues/2663#issuecomment-317109798
//---------------------------------------------------------------------
const path = require('path');

module.exports = {
process(src, filename /*, config, options */) {
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
},
};

0 comments on commit db99aaf

Please sign in to comment.