mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
fix: Support relative tsconfig paths on multiple levels in jest config (no-changelog) (#14162)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { compilerOptions } = require('./tsconfig.json');
|
||||
const { pathsToModuleNameMapper } = require('ts-jest')
|
||||
const { compilerOptions } = require('get-tsconfig').getTsconfig().config;
|
||||
|
||||
/** @type {import('ts-jest').TsJestGlobalOptions} */
|
||||
const tsJestOptions = {
|
||||
@@ -10,7 +11,6 @@ const tsJestOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
const { baseUrl, paths } = require('get-tsconfig').getTsconfig().config?.compilerOptions;
|
||||
|
||||
const isCoverageEnabled = process.env.COVERAGE_ENABLED === 'true';
|
||||
|
||||
@@ -24,15 +24,7 @@ const config = {
|
||||
'^.+\\.ts$': ['ts-jest', tsJestOptions],
|
||||
},
|
||||
// This resolve the path mappings from the tsconfig relative to each jest.config.js
|
||||
moduleNameMapper: Object.entries(paths || {}).reduce((acc, [path, [mapping]]) => {
|
||||
path = `^${path.replace(/\/\*$/, '/(.*)$')}`;
|
||||
mapping = mapping.replace(/^\.?\.\/(?:(.*)\/)?\*$/, '$1');
|
||||
mapping = mapping ? `/${mapping}` : '';
|
||||
acc[path] = mapping.startsWith('/test')
|
||||
? '<rootDir>' + mapping + '/$1'
|
||||
: '<rootDir>' + (baseUrl ? `/${baseUrl.replace(/^\.\//, '')}` : '') + mapping + '/$1';
|
||||
return acc;
|
||||
}, {}),
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: `<rootDir>${compilerOptions.baseUrl ? `/${compilerOptions.baseUrl.replace(/^\.\//, '')}` : ''}` }),
|
||||
setupFilesAfterEnv: ['jest-expect-message'],
|
||||
collectCoverage: isCoverageEnabled,
|
||||
coverageReporters: ['text-summary', 'lcov', 'html-spa'],
|
||||
|
||||
Reference in New Issue
Block a user