-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjest.config.js
More file actions
116 lines (104 loc) · 3.22 KB
/
jest.config.js
File metadata and controls
116 lines (104 loc) · 3.22 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
109
110
111
112
113
114
115
116
const path = require('path');
// Root directory for absolute path resolution
const rootDir = __dirname;
// Common module mapper for action packages (use absolute paths)
const commonModuleMapper = {
'^action-schema$': path.join(rootDir, 'common/action-schema/src/index.ts'),
'^trace-commands$': path.join(rootDir, 'common/trace-commands/src/index.ts'),
'^gh-inputs$': path.join(rootDir, 'common/gh-inputs/src/index.ts'),
'^pretty-errors$': path.join(rootDir, 'common/pretty-errors/src/index.ts')
};
// Transform config for TypeScript source files
const tsTransform = {
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: path.join(rootDir, 'tsconfig.test.json')
}]
};
// Transform config for ESM-only JS packages (e.g. @actions/* v3+)
const esmJsTransform = {
'^.+\\.m?js$': ['ts-jest', {
tsconfig: {
allowJs: true,
esModuleInterop: true,
resolveJsonModule: true,
target: 'ES2021',
module: 'CommonJS'
}
}]
};
// Base configuration shared across all projects
const baseConfig = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts'
],
// Custom resolver to handle ESM-only @actions/* v3+ package exports
resolver: path.join(rootDir, 'jest-resolver.js'),
// Allow transforming ESM-only node_modules (many deps are now ESM-only)
transformIgnorePatterns: [],
verbose: true
};
// Action packages (need moduleNameMapper)
const actionPackages = [
'b2-workflow',
'boost-clone',
'cmake-workflow',
'cpp-matrix',
'create-changelog',
'flamegraph',
'package-install',
'setup-clang',
'setup-cmake',
'setup-cpp',
'setup-gcc',
'setup-msvc',
'setup-program'
];
// Common packages (no moduleNameMapper needed)
const commonPackages = [
'common/action-schema',
'common/gh-inputs',
'common/pretty-errors',
'common/trace-commands'
];
// Utils packages (no moduleNameMapper needed)
const utilsPackages = [
'utils/update-data',
'utils/docs',
'utils/jsdoc-linter',
'utils/release'
];
// Generate project configs for actions
const actionProjects = actionPackages.map(pkg => ({
...baseConfig,
displayName: pkg,
rootDir: path.join(rootDir, pkg),
roots: ['<rootDir>/src'],
transform: { ...tsTransform, ...esmJsTransform },
moduleNameMapper: commonModuleMapper
}));
// Generate project configs for common modules
const commonProjects = commonPackages.map(pkg => ({
...baseConfig,
displayName: pkg.split('/')[1],
rootDir: path.join(rootDir, pkg),
roots: ['<rootDir>/src'],
transform: { ...tsTransform, ...esmJsTransform }
}));
// Generate project configs for utils modules
const utilsProjects = utilsPackages.map(pkg => ({
...baseConfig,
displayName: pkg.split('/')[1],
rootDir: path.join(rootDir, pkg),
roots: ['<rootDir>/src'],
transform: { ...tsTransform, ...esmJsTransform }
}));
module.exports = {
projects: [...actionProjects, ...commonProjects, ...utilsProjects],
coverageDirectory: path.join(rootDir, 'coverage')
};