From dfbe43ef0272cc6bfbea1f62ebaebc068abe37b3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 May 2022 13:22:38 +0200 Subject: [PATCH] Added missing configs to fixt tests with Jest 28 --- config/jest/cssTransform.js | 12 ++++++++++++ config/jest/fileTransform.js | 4 +++- config/jest/setupBeforeEnzyme.js | 4 ++++ jest.config.js | 10 +++++----- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 config/jest/cssTransform.js create mode 100644 config/jest/setupBeforeEnzyme.js diff --git a/config/jest/cssTransform.js b/config/jest/cssTransform.js new file mode 100644 index 00000000..85bf39b7 --- /dev/null +++ b/config/jest/cssTransform.js @@ -0,0 +1,12 @@ +// This is a custom Jest transformer turning style imports into empty objects. +// http://facebook.github.io/jest/docs/en/webpack.html + +module.exports = { + process() { + return { code: 'module.exports = {};' }; + }, + getCacheKey() { + // The output is always the same. + return 'cssTransform'; + }, +}; diff --git a/config/jest/fileTransform.js b/config/jest/fileTransform.js index 1567f853..46d0e641 100644 --- a/config/jest/fileTransform.js +++ b/config/jest/fileTransform.js @@ -24,6 +24,8 @@ module.exports = { };`; } - return `module.exports = ${assetFilename};`; + return { + code: `module.exports = ${assetFilename};` + }; }, }; diff --git a/config/jest/setupBeforeEnzyme.js b/config/jest/setupBeforeEnzyme.js new file mode 100644 index 00000000..71c20acd --- /dev/null +++ b/config/jest/setupBeforeEnzyme.js @@ -0,0 +1,4 @@ +import * as util from 'util'; + +global.TextEncoder = util.TextEncoder; +global.TextDecoder = util.TextDecoder; diff --git a/jest.config.js b/jest.config.js index 28433deb..70853185 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,7 +15,7 @@ module.exports = { lines: 85, }, }, - setupFiles: ['/config/jest/setupEnzyme.js'], + setupFiles: ['/config/jest/setupBeforeEnzyme.js', '/config/jest/setupEnzyme.js'], setupFilesAfterEnv: ['/config/jest/setupTests.ts'], testMatch: ['/test/**/*.test.{ts,tsx}'], testEnvironment: 'jsdom', @@ -24,18 +24,18 @@ module.exports = { }, transform: { '^.+\\.(ts|tsx|js)$': '/node_modules/babel-jest', - '^(?!.*\\.(ts|tsx|js|json)$)': '/config/jest/fileTransform.js', + '^.+\\.scss$': '/config/jest/cssTransform.js', + '^(?!.*\\.(ts|tsx|js|json|scss)$)': '/config/jest/fileTransform.js', }, transformIgnorePatterns: [ '/.stryker-tmp', - 'node_modules\/(?!(\@react-leaflet|react-leaflet|leaflet|react-chartjs-2)\/)', + 'node_modules\/(?!(\@react-leaflet|react-leaflet|leaflet|react-chartjs-2|react-colorful)\/)', '^.+\\.module\\.scss$', ], moduleNameMapper: { '^.+\\.module\\.scss$': 'identity-obj-proxy', - // Reactstrap module resolution does not work in jest for some reason. Manually mapping it solves the problem - 'reactstrap': '/node_modules/reactstrap/dist/reactstrap.umd.js', 'react-chartjs-2': '/node_modules/react-chartjs-2/dist/index.js', + 'uuid': '/node_modules/uuid/dist/index.js', }, moduleFileExtensions: ['js', 'ts', 'tsx', 'json'], };