From 52d295c09cdfdbf59fd984dae6286143875cbfea Mon Sep 17 00:00:00 2001 From: PrudhviRaj5 Date: Thu, 30 Nov 2017 01:14:16 +0530 Subject: [PATCH] added jest configs for handling all files --- config/jest/assetsTransformer.js | 7 +++++++ shim.js => config/jest/shim.js | 2 +- package.json | 6 +++++- tests/components/App.test.js | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 config/jest/assetsTransformer.js rename shim.js => config/jest/shim.js (94%) diff --git a/config/jest/assetsTransformer.js b/config/jest/assetsTransformer.js new file mode 100644 index 00000000..5eadded9 --- /dev/null +++ b/config/jest/assetsTransformer.js @@ -0,0 +1,7 @@ +const path = require('path'); + +module.exports = { + process(src, filename, config, options) { + return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; + }, +}; diff --git a/shim.js b/config/jest/shim.js similarity index 94% rename from shim.js rename to config/jest/shim.js index 743f1127..b7e619ba 100644 --- a/shim.js +++ b/config/jest/shim.js @@ -2,4 +2,4 @@ global.requestAnimationFrame = function(callback) { setTimeout(callback, 0); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 85aa556f..992e8190 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,16 @@ "license": "MIT", "jest": { "setupFiles": [ - "/shim.js" + "/config/jest/shim.js" ], "mapCoverage": true, "collectCoverageFrom": [ "app/**/*.{js,jsx,ts,tsx}" ], + "moduleNameMapper": { + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/config/jest/assetsTransformer.js", + "\\.(css|less)$": "/config/jest/assetsTransformer.js" + }, "testMatch": [ "**/?(*.)(spec|test).js?(x)" ] diff --git a/tests/components/App.test.js b/tests/components/App.test.js index 43664d0e..b849e026 100644 --- a/tests/components/App.test.js +++ b/tests/components/App.test.js @@ -1,8 +1,9 @@ import React from 'react'; import { shallow, configure } from 'enzyme'; -import App from '../../app/components/App'; import Adapter from 'enzyme-adapter-react-16'; +import App from '../../app/components/App'; + configure({ adapter: new Adapter() }); describe('App Component', () => {