-
Notifications
You must be signed in to change notification settings - Fork 58.1k
Expand file tree
/
Copy pathjest.config.js
More file actions
108 lines (99 loc) · 3.94 KB
/
jest.config.js
File metadata and controls
108 lines (99 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('get-tsconfig').getTsconfig().config;
const { resolve } = require('path');
/** @type {import('ts-jest').TsJestTransformerOptions} */
const tsJestOptions = {
tsconfig: {
...compilerOptions,
declaration: false,
sourceMap: true,
rootDir: '.',
// Force the transpile-only path for tests. Without this, ts-jest runs
// the full type-checker on every transformed file, which combined with
// aggressive worker recycling (workerIdleMemoryLimit) makes test runs
// ~4-5x slower. Package builds and `pnpm typecheck` read the package
// tsconfig directly and are unaffected.
isolatedModules: true,
// Relax strictness for cross-package imports. ts-jest applies the host
// package's tsconfig to every file it transforms, including imports
// from packages like nodes-base that disable these in their own
// tsconfig. The host package's own `pnpm typecheck` is unaffected.
noImplicitReturns: false,
noUncheckedIndexedAccess: false,
noImplicitOverride: false,
useUnknownInCatchVariables: false,
},
};
const isCoverageEnabled = process.env.COVERAGE_ENABLED === 'true';
const esmDependencies = [
'pdfjs-dist',
'openid-client',
'oauth4webapi',
'jose',
'p-retry',
'is-network-error',
'uuid',
// Add other ESM dependencies that need to be transformed here
];
const esmDependenciesPattern = esmDependencies.join('|');
// On Windows, Jest passes raw backslash paths to transform/ignore pattern regexes
// without normalizing separators, so we must match both / and \.
const isWindows = process.platform === 'win32';
const sep = isWindows ? '[/\\\\]' : '/';
const nonSep = isWindows ? '[^/\\\\]' : '[^/]';
const esmDependenciesRegex = `node_modules${sep}(${esmDependenciesPattern})${sep}.+\\.m?js$`;
/** @type {import('jest').Config} */
const config = {
verbose: false,
testEnvironment: 'node',
testRegex: '\\.(test|spec)\\.(js|ts)$',
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
transform: {
'^.+\\.ts$': ['ts-jest', tsJestOptions],
[esmDependenciesRegex]: [
'babel-jest',
{
presets: ['@babel/preset-env'],
plugins: ['babel-plugin-transform-import-meta'],
},
],
},
transformIgnorePatterns: [
// Exclude the pnpm virtual store dir (.pnpm) and the ESM deps from being ignored.
`${sep}node_modules${sep}(?!\\.pnpm|${esmDependenciesPattern})${sep}`,
// On Windows with pnpm, ESM deps live inside the virtual store (.pnpm) and are
// accessed via hardlinks (no symlinks), so their path goes through
// .pnpm/<pkg@version>/node_modules/<pkg>/... — exclude ESM deps from being ignored there too.
...(isWindows
? [`${sep}\\.pnpm${sep}${nonSep}+${sep}node_modules${sep}(?!${esmDependenciesPattern})${sep}`]
: []),
],
// This resolve the path mappings from the tsconfig relative to each jest.config.js
moduleNameMapper: {
'^@n8n/utils$': resolve(__dirname, 'packages/@n8n/utils/dist/index.cjs'),
// jest-resolve@29 doesn't honor `./lib/*` subpath patterns in @anthropic-ai/sdk's exports map
'^@anthropic-ai/sdk/lib/(.*)$': '@anthropic-ai/sdk/lib/$1.js',
// Core uses vitest-mock-extended (ESM-only) for its own tests; route the
// shim to a CJS-friendly variant for Jest-based consumers (nodes-base, cli).
'^(\\./|\\.\\./nodes-testing/)mock-extended$': resolve(
__dirname,
'packages/core/nodes-testing/mock-extended.jest.cjs',
),
...(compilerOptions?.paths
? pathsToModuleNameMapper(compilerOptions.paths, {
prefix: `<rootDir>${compilerOptions.baseUrl ? `/${compilerOptions.baseUrl.replace(/^\.\//, '')}` : ''}`,
})
: {}),
},
setupFilesAfterEnv: ['jest-expect-message'],
restoreMocks: true,
collectCoverage: isCoverageEnabled,
coverageReporters: ['text-summary', 'lcov', 'html-spa'],
workerIdleMemoryLimit: '1MB',
};
if (process.env.CI === 'true') {
config.collectCoverageFrom = ['src/**/*.ts'];
config.reporters = ['default', 'jest-junit'];
config.coverageReporters = ['cobertura'];
}
module.exports = config;