diff --git a/fileTransformer.js b/fileTransformer.js new file mode 100644 index 0000000000..e48b35be96 --- /dev/null +++ b/fileTransformer.js @@ -0,0 +1,8 @@ +const path = require('path') + +// https://jestjs.io/docs/code-transformation#transforming-images-to-their-path +module.exports = { + process(src, filename, config, options) { + return `module.exports = ${JSON.stringify(path.basename(filename))};` + }, +} diff --git a/jest.config.js b/jest.config.js index 55b217d341..d67116de92 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,8 @@ module.exports = { moduleDirectories: ['node_modules', 'src/tests'], transform: { '^.+\\.(ts|tsx)?$': 'ts-jest/dist', + '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': + '/fileTransformer.js', }, transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'], setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],