From 98b6122bec7b44a9f5756d99c834a371811f0afd Mon Sep 17 00:00:00 2001 From: fargito Date: Mon, 28 Mar 2022 11:06:23 +0200 Subject: [PATCH] feat: use moduleDirectories option in jest to avoid moduleNameMapper pain --- backend/core/jest.config.ts | 5 ++++- backend/forum/jest.config.ts | 5 ++++- backend/users/jest.config.ts | 5 ++++- frontend/app/jest.config.ts | 10 ---------- frontend/shared/jest.config.ts | 3 --- packages/configuration/src/config/jest.config.ts | 1 + tools/generators/service/files/jest.config.ts__tmpl__ | 5 ++++- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/core/jest.config.ts b/backend/core/jest.config.ts index 83a06755..7024fdd6 100644 --- a/backend/core/jest.config.ts +++ b/backend/core/jest.config.ts @@ -1,3 +1,6 @@ import { jestConfig } from '@swarmion-starter/configuration'; -export default jestConfig; +export default { + ...jestConfig, + moduleDirectories: ['node_modules', ''], +}; diff --git a/backend/forum/jest.config.ts b/backend/forum/jest.config.ts index 83a06755..7024fdd6 100644 --- a/backend/forum/jest.config.ts +++ b/backend/forum/jest.config.ts @@ -1,3 +1,6 @@ import { jestConfig } from '@swarmion-starter/configuration'; -export default jestConfig; +export default { + ...jestConfig, + moduleDirectories: ['node_modules', ''], +}; diff --git a/backend/users/jest.config.ts b/backend/users/jest.config.ts index 83a06755..7024fdd6 100644 --- a/backend/users/jest.config.ts +++ b/backend/users/jest.config.ts @@ -1,3 +1,6 @@ import { jestConfig } from '@swarmion-starter/configuration'; -export default jestConfig; +export default { + ...jestConfig, + moduleDirectories: ['node_modules', ''], +}; diff --git a/frontend/app/jest.config.ts b/frontend/app/jest.config.ts index 65f81722..40759a8b 100644 --- a/frontend/app/jest.config.ts +++ b/frontend/app/jest.config.ts @@ -6,16 +6,6 @@ const config: InitialOptionsTsJest = { ...jestConfig, testEnvironment: 'jsdom', moduleNameMapper: { - '^__fixtures__(/(.*)|)$': '/src/__fixtures__/$1', - '^components(/(.*)|)$': '/src/components/$1', - '^hooks(/(.*)|)$': '/src/hooks/$1', - '^pages(/(.*)|)$': '/src/pages/$1', - '^services(/(.*)|)$': '/src/services/$1', - '^AppRoutes$': '/src/AppRoutes', - '^store(/(.*)|)$': '/src/store/$1', - '^testUtils(/(.*)|)$': '/src/testUtils/$1', - '^theme(/(.*)|)$': '/src/theme/$1', - '^translations(/(.*)|)$': '/src/translations/$1', '@react-hookz/web/esnext': '@react-hookz/web', '^.*\\.svg$': '/src/__mocks__/svgrMock.ts', }, diff --git a/frontend/shared/jest.config.ts b/frontend/shared/jest.config.ts index 7b2f9ec6..b3f689e8 100644 --- a/frontend/shared/jest.config.ts +++ b/frontend/shared/jest.config.ts @@ -5,9 +5,6 @@ import { jestConfig } from '@swarmion-starter/configuration'; const config: Config.InitialOptions = { ...jestConfig, testEnvironment: 'jsdom', - moduleNameMapper: { - '^components(/(.*)|)$': '/src/components/$1', - }, setupFiles: ['dotenv-flow/config'], setupFilesAfterEnv: ['/jest.setupAfterEnv.ts'], }; diff --git a/packages/configuration/src/config/jest.config.ts b/packages/configuration/src/config/jest.config.ts index c5c96f04..6a7e27ed 100644 --- a/packages/configuration/src/config/jest.config.ts +++ b/packages/configuration/src/config/jest.config.ts @@ -14,6 +14,7 @@ const config: InitialOptionsTsJest = { coverageReporters: ['json', ['lcov', { projectRoot: './' }]], testPathIgnorePatterns: ['/node_modules/', '/dist/'], modulePathIgnorePatterns: ['/dist/'], + moduleDirectories: ['node_modules', '/src'], }; export default config; diff --git a/tools/generators/service/files/jest.config.ts__tmpl__ b/tools/generators/service/files/jest.config.ts__tmpl__ index 5045304b..881ab54f 100644 --- a/tools/generators/service/files/jest.config.ts__tmpl__ +++ b/tools/generators/service/files/jest.config.ts__tmpl__ @@ -1,3 +1,6 @@ import { jestConfig } from '@<%= workspaceName %>/configuration'; -export default jestConfig; +export default { + ...jestConfig, + moduleDirectories: ['node_modules', ''], +};