From a670a73fd019d03090e93cb4ab9a0603d0cc5efb Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 2 Nov 2018 16:32:51 -0400 Subject: [PATCH] update file mock to return file name --- __mocks__/fileMock.js | 8 +++++++- jest.config.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/__mocks__/fileMock.js b/__mocks__/fileMock.js index 86059f3629..0bf40cb419 100644 --- a/__mocks__/fileMock.js +++ b/__mocks__/fileMock.js @@ -1 +1,7 @@ -module.exports = 'test-file-stub'; +const path = require('path'); + +module.exports = { + process (src, filename) { + return `module.exports=${JSON.stringify(path.basename(filename))};`; + }, +}; diff --git a/jest.config.js b/jest.config.js index cf3d1a6f92..c3730195c8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,7 +3,6 @@ module.exports = { 'src/**/*.{js,jsx}' ], moduleNameMapper: { - '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/__mocks__/fileMock.js', '\\.(css|scss|less)$': '/__mocks__/styleMock.js' }, setupTestFrameworkScriptFile: '/jest.setup.js', @@ -13,7 +12,8 @@ module.exports = { testEnvironment: 'jsdom', testURL: 'http://127.0.0.1:3001', transform: { - '^.+\\.(js|jsx)$': 'babel-jest' + '^.+\\.(js|jsx)$': 'babel-jest', + '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/__mocks__/fileMock.js', }, transformIgnorePatterns: [ '[/\\\\]node_modules[/\\\\].+\\.(?!(axios)/)(js|jsx)$'