From edf26f6f9950c05ee7d0f6ccf492996f2eade509 Mon Sep 17 00:00:00 2001 From: "yuqi.pyq" Date: Thu, 23 May 2024 15:25:44 +0800 Subject: [PATCH] chore: transform d3-color in jest --- jest.config.js | 11 +++++++---- jest.node.config.js | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/jest.config.js b/jest.config.js index 617cbe372..d38c29044 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,12 @@ const packages = readdirSync(basePath).filter((name) => { return lstatSync(path.join(basePath, name)).isDirectory(); }); +// Installing third-party modules by tnpm or cnpm will name modules with underscore as prefix. +// In this case _{module} is also necessary. +const esm = ['internmap', 'd3-*', 'lodash-es'] + .map((d) => `_${d}|${d}`) + .join('|'); + // @see https://blog.ah.technology/a-guide-through-the-wild-wild-west-of-setting-up-a-mono-repo-part-2-adding-jest-with-a-breeze-16e08596f0de const moduleNameMapper = { ...packages.reduce( @@ -60,8 +66,5 @@ module.exports = { }, moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], modulePathIgnorePatterns: ['dist'], - transformIgnorePatterns: [ - // @see https://stackoverflow.com/a/69179139 - '/node_modules/(?!d3|d3-array|internmap|delaunator|robust-predicates)', - ], + transformIgnorePatterns: [`/node_modules/(?!(?:.pnpm/)?(${esm}))`], }; diff --git a/jest.node.config.js b/jest.node.config.js index 51321756b..69ef4cc19 100644 --- a/jest.node.config.js +++ b/jest.node.config.js @@ -6,6 +6,12 @@ const packages = readdirSync(basePath).filter((name) => { return lstatSync(path.join(basePath, name)).isDirectory(); }); +// Installing third-party modules by tnpm or cnpm will name modules with underscore as prefix. +// In this case _{module} is also necessary. +const esm = ['internmap', 'd3-*', 'lodash-es'] + .map((d) => `_${d}|${d}`) + .join('|'); + // @see https://blog.ah.technology/a-guide-through-the-wild-wild-west-of-setting-up-a-mono-repo-part-2-adding-jest-with-a-breeze-16e08596f0de const moduleNameMapper = { ...packages.reduce( @@ -40,12 +46,8 @@ module.exports = { }, moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], modulePathIgnorePatterns: ['dist'], - transformIgnorePatterns: [ - // @see https://stackoverflow.com/a/69179139 - '/node_modules/(?!d3|d3-array|internmap|delaunator|robust-predicates)', - ], globalSetup: './scripts/jest/setup.js', globalTeardown: './scripts/jest/teardown.js', testEnvironment: './scripts/jest/environment.js', - testPathIgnorePatterns: ['/__tests__/main.ts'], + transformIgnorePatterns: [`/node_modules/(?!(?:.pnpm/)?(${esm}))`], };