diff --git a/package.json b/package.json index d09a6ade2..49f5c934a 100644 --- a/package.json +++ b/package.json @@ -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)$": "/tools/fileMock.js" - } + "moduleNameMapper": { + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/tools/assetsTransformer.js", + "\\.(css|less)$": "/tools/assetsTransformer.js" + } }, "babel": { "presets": [ diff --git a/tools/assetsTransformer.js b/tools/assetsTransformer.js new file mode 100644 index 000000000..8beaca7f0 --- /dev/null +++ b/tools/assetsTransformer.js @@ -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)) + ';'; + }, +};