mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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} */
|
/** @type {import('ts-jest').TsJestGlobalOptions} */
|
||||||
const tsJestOptions = {
|
const tsJestOptions = {
|
||||||
@@ -10,7 +11,6 @@ const tsJestOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const { baseUrl, paths } = require('get-tsconfig').getTsconfig().config?.compilerOptions;
|
|
||||||
|
|
||||||
const isCoverageEnabled = process.env.COVERAGE_ENABLED === 'true';
|
const isCoverageEnabled = process.env.COVERAGE_ENABLED === 'true';
|
||||||
|
|
||||||
@@ -24,15 +24,7 @@ const config = {
|
|||||||
'^.+\\.ts$': ['ts-jest', tsJestOptions],
|
'^.+\\.ts$': ['ts-jest', tsJestOptions],
|
||||||
},
|
},
|
||||||
// This resolve the path mappings from the tsconfig relative to each jest.config.js
|
// This resolve the path mappings from the tsconfig relative to each jest.config.js
|
||||||
moduleNameMapper: Object.entries(paths || {}).reduce((acc, [path, [mapping]]) => {
|
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: `<rootDir>${compilerOptions.baseUrl ? `/${compilerOptions.baseUrl.replace(/^\.\//, '')}` : ''}` }),
|
||||||
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;
|
|
||||||
}, {}),
|
|
||||||
setupFilesAfterEnv: ['jest-expect-message'],
|
setupFilesAfterEnv: ['jest-expect-message'],
|
||||||
collectCoverage: isCoverageEnabled,
|
collectCoverage: isCoverageEnabled,
|
||||||
coverageReporters: ['text-summary', 'lcov', 'html-spa'],
|
coverageReporters: ['text-summary', 'lcov', 'html-spa'],
|
||||||
|
|||||||
Reference in New Issue
Block a user