From 94951716e65702594ecd5acd9b55b71b8a19b93d Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 29 Nov 2022 12:31:50 +0000 Subject: [PATCH] Jest transform workaround for ESM-only packages Enables Babel transform for ESM-only packages (to CommonJS) until Jest supports ESM https://jestjs.io/docs/ecmascript-modules Babel ignores `node_modules` by default --- jest.config.js => jest.config.mjs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) rename jest.config.js => jest.config.mjs (90%) diff --git a/jest.config.js b/jest.config.mjs similarity index 90% rename from jest.config.js rename to jest.config.mjs index e8d7d6c57e..8dbaaf940c 100644 --- a/jest.config.js +++ b/jest.config.mjs @@ -14,10 +14,19 @@ const config = { // See: https://jestjs.io/docs/ecmascript-modules transform: { '^.+\\.m?js$': ['babel-jest', { rootMode: 'upward' }] - } + }, + + // Enable Babel transforms for ESM-only node_modules + // See: https://jestjs.io/docs/ecmascript-modules + transformIgnorePatterns: [ + `/node_modules/(?!${[ + 'del', + 'slash' + ].join('|')}/)` + ] } -module.exports = { +export default { collectCoverageFrom: ['./src/**/*.{js,mjs}'], projects: [ {