@jmlweb/jest-config 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @jmlweb/jest-config
2
+
3
+ ## 0.0.0
4
+
5
+ ### Added
6
+
7
+ - Initial release
8
+ - Base Jest configuration with TypeScript support
9
+ - Coverage configuration with 80% thresholds
10
+ - Factory function for custom configurations
11
+ - Default export for zero-config usage
12
+ - Support for Node.js and jsdom environments
package/README.md ADDED
@@ -0,0 +1,263 @@
1
+ # @jmlweb/jest-config
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/jest-config)](https://www.npmjs.com/package/@jmlweb/jest-config)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20.11.0-339933.svg)](https://nodejs.org/)
6
+ [![Jest](https://img.shields.io/badge/Jest-29.0%2B-C21325.svg)](https://jestjs.io/)
7
+ [![ts-jest](https://img.shields.io/badge/ts--jest-29.0%2B-C21325.svg)](https://kulshekhar.github.io/ts-jest/)
8
+
9
+ > Base Jest configuration for jmlweb projects. TypeScript support, coverage settings, and sensible defaults out of the box.
10
+
11
+ ## ✨ Features
12
+
13
+ - 🔧 **TypeScript Support**: Configured for TypeScript projects with ts-jest
14
+ - 📊 **Coverage Configuration**: Pre-configured with 80% coverage thresholds
15
+ - 🎯 **Sensible Defaults**: Node.js environment, optimized test execution, clear mocks
16
+ - ⚡ **Performance Optimized**: Efficient test execution with proper module isolation
17
+ - 🚀 **Easy Extension**: Factory function for easy customization
18
+ - 📦 **Zero Config**: Works out of the box with minimal setup
19
+
20
+ ## 📦 Installation
21
+
22
+ ```bash
23
+ npm install --save-dev @jmlweb/jest-config jest ts-jest @types/jest
24
+ ```
25
+
26
+ ## 🚀 Quick Start
27
+
28
+ Create a `jest.config.ts` file in your project root:
29
+
30
+ ```typescript
31
+ import jestConfig from '@jmlweb/jest-config';
32
+
33
+ export default jestConfig;
34
+ ```
35
+
36
+ Or use the factory function for customization:
37
+
38
+ ```typescript
39
+ import { createJestConfig } from '@jmlweb/jest-config';
40
+
41
+ export default createJestConfig({
42
+ testEnvironment: 'jsdom',
43
+ setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
44
+ });
45
+ ```
46
+
47
+ ## 💡 Examples
48
+
49
+ ### Basic Setup
50
+
51
+ ```typescript
52
+ // jest.config.ts
53
+ import jestConfig from '@jmlweb/jest-config';
54
+
55
+ export default jestConfig;
56
+ ```
57
+
58
+ ### With Project-Specific Overrides
59
+
60
+ ```typescript
61
+ // jest.config.ts
62
+ import { createJestConfig } from '@jmlweb/jest-config';
63
+
64
+ export default createJestConfig({
65
+ testEnvironment: 'jsdom',
66
+ setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
67
+ testTimeout: 10000,
68
+ coverageThreshold: {
69
+ global: {
70
+ lines: 90,
71
+ functions: 90,
72
+ branches: 85,
73
+ statements: 90,
74
+ },
75
+ },
76
+ });
77
+ ```
78
+
79
+ ### React/JSX Project Example
80
+
81
+ ```typescript
82
+ // jest.config.ts
83
+ import { createJestConfig } from '@jmlweb/jest-config';
84
+
85
+ export default createJestConfig({
86
+ testEnvironment: 'jsdom',
87
+ setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
88
+ moduleNameMapper: {
89
+ '^@/(.*)$': '<rootDir>/src/$1',
90
+ },
91
+ });
92
+ ```
93
+
94
+ ### Lower Coverage Thresholds
95
+
96
+ ```typescript
97
+ // jest.config.ts
98
+ import { createJestConfig } from '@jmlweb/jest-config';
99
+
100
+ export default createJestConfig({
101
+ coverageThreshold: {
102
+ global: {
103
+ lines: 60,
104
+ functions: 60,
105
+ branches: 60,
106
+ statements: 60,
107
+ },
108
+ },
109
+ });
110
+ ```
111
+
112
+ ### Custom Test Patterns
113
+
114
+ ```typescript
115
+ // jest.config.ts
116
+ import { createJestConfig } from '@jmlweb/jest-config';
117
+
118
+ export default createJestConfig({
119
+ testMatch: ['**/__tests__/**/*.ts', '**/*.test.ts'],
120
+ collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
121
+ });
122
+ ```
123
+
124
+ ## 📋 Configuration Details
125
+
126
+ ### Default Settings
127
+
128
+ | Setting | Value | Description |
129
+ | ------------------------------------- | -------------------------------------- | ---------------------------------------- |
130
+ | `testEnvironment` | `node` | Node.js environment by default |
131
+ | `moduleFileExtensions` | `['ts', 'tsx', 'js', 'jsx', 'json']` | Supported file extensions |
132
+ | `testMatch` | `['**/*.{test,spec}.{ts,tsx,js,jsx}']` | Test file patterns |
133
+ | `testTimeout` | `5000` | Test timeout in milliseconds (5 seconds) |
134
+ | `coverageThreshold.global.lines` | `80` | Minimum line coverage |
135
+ | `coverageThreshold.global.functions` | `80` | Minimum function coverage |
136
+ | `coverageThreshold.global.branches` | `80` | Minimum branch coverage |
137
+ | `coverageThreshold.global.statements` | `80` | Minimum statement coverage |
138
+ | `verbose` | `true` | Detailed test output |
139
+ | `clearMocks` | `true` | Clear mocks between tests |
140
+ | `restoreMocks` | `true` | Restore mocks after each test |
141
+
142
+ ### Coverage Exclusions
143
+
144
+ The following patterns are excluded from coverage by default:
145
+
146
+ - `**/*.d.ts` - TypeScript declaration files
147
+ - `**/*.config.{ts,js}` - Configuration files
148
+ - `**/dist/**` - Build output
149
+ - `**/build/**` - Build directories
150
+ - `**/node_modules/**` - Dependencies
151
+ - `**/coverage/**` - Coverage reports
152
+ - `**/*.test.{ts,tsx,js,jsx}` - Test files
153
+ - `**/*.spec.{ts,tsx,js,jsx}` - Spec files
154
+
155
+ ### Test File Patterns
156
+
157
+ Tests are automatically discovered from:
158
+
159
+ - `**/*.test.{ts,tsx,js,jsx}`
160
+ - `**/*.spec.{ts,tsx,js,jsx}`
161
+
162
+ ### Coverage Reporters
163
+
164
+ - `text` - Text summary in terminal
165
+ - `json` - JSON format for CI/CD integration
166
+ - `html` - HTML coverage report (generated in `coverage/` directory)
167
+
168
+ ## 🎯 When to Use
169
+
170
+ Use this configuration when you want:
171
+
172
+ - ✅ Consistent testing setup across projects using Jest
173
+ - ✅ TypeScript support out of the box
174
+ - ✅ Coverage thresholds enforced
175
+ - ✅ Sensible defaults for Node.js and browser projects
176
+ - ✅ Easy customization and extension
177
+
178
+ **For projects using Vitest**, use [`@jmlweb/vitest-config`](../vitest-config) instead.
179
+
180
+ ## 🔧 Extending the Configuration
181
+
182
+ You can extend or override the configuration for your specific needs:
183
+
184
+ ```typescript
185
+ import { createJestConfig } from '@jmlweb/jest-config';
186
+
187
+ export default createJestConfig({
188
+ // Add custom setup files
189
+ setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
190
+
191
+ // Custom test patterns
192
+ testMatch: ['**/*.test.ts', '**/__tests__/**/*.ts'],
193
+
194
+ // Custom environment
195
+ testEnvironment: 'jsdom',
196
+
197
+ // Path aliases
198
+ moduleNameMapper: {
199
+ '^@/(.*)$': '<rootDir>/src/$1',
200
+ '^~/(.*)$': '<rootDir>/src/$1',
201
+ },
202
+ });
203
+ ```
204
+
205
+ ## 📝 Usage with Scripts
206
+
207
+ Add test scripts to your `package.json`:
208
+
209
+ ```json
210
+ {
211
+ "scripts": {
212
+ "test": "jest",
213
+ "test:watch": "jest --watch",
214
+ "test:coverage": "jest --coverage",
215
+ "test:ci": "jest --ci --coverage --maxWorkers=2"
216
+ }
217
+ }
218
+ ```
219
+
220
+ Then run:
221
+
222
+ ```bash
223
+ npm run test # Run tests once
224
+ npm run test:watch # Run tests in watch mode
225
+ npm run test:coverage # Run tests with coverage
226
+ npm run test:ci # Run tests in CI mode
227
+ ```
228
+
229
+ ### TypeScript Configuration
230
+
231
+ The configuration uses `ts-jest` for TypeScript support. The default transform configuration includes:
232
+
233
+ - `esModuleInterop: true` - Allows default imports from CommonJS modules
234
+ - `allowSyntheticDefaultImports: true` - Allows default imports from modules with no default export
235
+
236
+ These settings ensure compatibility with modern TypeScript projects.
237
+
238
+ ## 📋 Requirements
239
+
240
+ - **Node.js** >= 20.11.0
241
+ - **Jest** >= 29.0.0
242
+ - **ts-jest** >= 29.0.0
243
+ - **@types/jest** >= 29.0.0
244
+ - **TypeScript** project (recommended, but not required)
245
+
246
+ ## 📦 Peer Dependencies
247
+
248
+ This package requires the following peer dependencies:
249
+
250
+ - `jest` (>=29.0.0)
251
+ - `ts-jest` (>=29.0.0)
252
+ - `@types/jest` (>=29.0.0)
253
+
254
+ ## 🔗 Related Packages
255
+
256
+ - [`@jmlweb/vitest-config`](../vitest-config) - Vitest configuration for modern testing
257
+ - [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint config for TypeScript projects
258
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
259
+ - [`@jmlweb/tsconfig-base`](../tsconfig-base) - TypeScript configuration
260
+
261
+ ## 📄 License
262
+
263
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createJestConfig: () => createJestConfig,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var createJestConfig = (options = {}) => {
28
+ const {
29
+ testEnvironment = "node",
30
+ moduleFileExtensions = ["ts", "tsx", "js", "jsx", "json"],
31
+ testMatch = ["**/*.{test,spec}.{ts,tsx,js,jsx}"],
32
+ testPathIgnorePatterns = [
33
+ "/node_modules/",
34
+ "/dist/",
35
+ "/build/",
36
+ "/.git/",
37
+ "/.cache/"
38
+ ],
39
+ coverageThreshold = {
40
+ global: {
41
+ lines: 80,
42
+ functions: 80,
43
+ branches: 80,
44
+ statements: 80
45
+ }
46
+ },
47
+ collectCoverageFrom = ["src/**/*.{ts,tsx,js,jsx}"],
48
+ coveragePathIgnorePatterns = [
49
+ "/node_modules/",
50
+ "/dist/",
51
+ "/build/",
52
+ "/coverage/",
53
+ ".*\\.d\\.ts$",
54
+ ".*\\.config\\.(ts|js)$",
55
+ ".*\\.test\\.(ts|tsx|js|jsx)$",
56
+ ".*\\.spec\\.(ts|tsx|js|jsx)$"
57
+ ],
58
+ coverageReporters = ["text", "json", "html"],
59
+ setupFilesAfterEnv = [],
60
+ moduleNameMapper = {},
61
+ transform = {
62
+ "^.+\\.tsx?$": [
63
+ "ts-jest",
64
+ {
65
+ tsconfig: {
66
+ esModuleInterop: true,
67
+ allowSyntheticDefaultImports: true
68
+ }
69
+ }
70
+ ]
71
+ },
72
+ testTimeout = 5e3
73
+ } = options;
74
+ const config2 = {
75
+ // Test environment
76
+ testEnvironment,
77
+ // Module file extensions
78
+ moduleFileExtensions,
79
+ // Test file patterns
80
+ testMatch,
81
+ // Paths to ignore when looking for test files
82
+ testPathIgnorePatterns,
83
+ // Coverage configuration
84
+ collectCoverage: false,
85
+ // Disable by default, enable with --coverage flag
86
+ collectCoverageFrom,
87
+ coveragePathIgnorePatterns,
88
+ coverageThreshold,
89
+ coverageReporters,
90
+ // Setup files
91
+ setupFilesAfterEnv: setupFilesAfterEnv.length > 0 ? setupFilesAfterEnv : void 0,
92
+ // Module name mapping for path aliases
93
+ moduleNameMapper: Object.keys(moduleNameMapper).length > 0 ? moduleNameMapper : void 0,
94
+ // Transform configuration for TypeScript
95
+ transform,
96
+ // Test timeout
97
+ testTimeout,
98
+ // Verbose output for clearer test results
99
+ verbose: true,
100
+ // Clear mocks between tests
101
+ clearMocks: true,
102
+ // Restore mocks after each test
103
+ restoreMocks: true,
104
+ // Reset modules between tests
105
+ resetModules: false
106
+ };
107
+ Object.keys(config2).forEach((key) => {
108
+ if (config2[key] === void 0) {
109
+ delete config2[key];
110
+ }
111
+ });
112
+ return config2;
113
+ };
114
+ var config = createJestConfig();
115
+ var index_default = config;
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ createJestConfig
119
+ });
@@ -0,0 +1,121 @@
1
+ import { Config } from 'jest';
2
+
3
+ /**
4
+ * Options for creating a Jest configuration
5
+ */
6
+ interface JestConfigOptions {
7
+ /**
8
+ * Test environment (node, jsdom, etc.)
9
+ * @default 'node'
10
+ */
11
+ testEnvironment?: 'node' | 'jsdom' | string;
12
+ /**
13
+ * Array of file extensions Jest will look for
14
+ * @default ['ts', 'tsx', 'js', 'jsx']
15
+ */
16
+ moduleFileExtensions?: string[];
17
+ /**
18
+ * Array of file patterns for test files
19
+ * @default ['**\/*.{test,spec}.{ts,tsx,js,jsx}']
20
+ */
21
+ testMatch?: string[];
22
+ /**
23
+ * Array of patterns to skip when looking for test files
24
+ * @default ['**\/node_modules\/**', '**\/dist\/**', '**\/build\/**']
25
+ */
26
+ testPathIgnorePatterns?: string[];
27
+ /**
28
+ * Coverage thresholds
29
+ * @default { global: { lines: 80, functions: 80, branches: 80, statements: 80 } }
30
+ */
31
+ coverageThreshold?: Config['coverageThreshold'];
32
+ /**
33
+ * Array of patterns to include in coverage
34
+ * @default ['src\/**\/*.{ts,tsx,js,jsx}']
35
+ */
36
+ collectCoverageFrom?: string[];
37
+ /**
38
+ * Array of patterns to exclude from coverage
39
+ * @default ['**\/*.d.ts', '**\/*.config.{ts,js}', '**\/dist\/**', '**\/build\/**', '**\/node_modules\/**', '**\/coverage\/**', '**\/*.test.{ts,tsx,js,jsx}', '**\/*.spec.{ts,tsx,js,jsx}']
40
+ */
41
+ coveragePathIgnorePatterns?: string[];
42
+ /**
43
+ * Array of reporters for coverage
44
+ * @default ['text', 'json', 'html']
45
+ */
46
+ coverageReporters?: Config['coverageReporters'];
47
+ /**
48
+ * Array of setup files to run before each test file
49
+ * @default []
50
+ */
51
+ setupFilesAfterEnv?: string[];
52
+ /**
53
+ * Module name mapper for path aliases
54
+ * @default {}
55
+ */
56
+ moduleNameMapper?: Record<string, string | string[]>;
57
+ /**
58
+ * Transform configuration
59
+ * @default { '^.+\\.tsx?$': ['ts-jest', { tsconfig: { esModuleInterop: true, allowSyntheticDefaultImports: true } }] }
60
+ */
61
+ transform?: Record<string, string | [string, Record<string, unknown>]>;
62
+ /**
63
+ * Test timeout in milliseconds
64
+ * @default 5000
65
+ */
66
+ testTimeout?: number;
67
+ }
68
+ /**
69
+ * Creates a Jest configuration with TypeScript support, coverage settings, and sensible defaults.
70
+ * This configuration provides a solid foundation for testing TypeScript projects.
71
+ *
72
+ * Features:
73
+ * - TypeScript support via ts-jest
74
+ * - Coverage configuration with 80% thresholds
75
+ * - Node.js environment by default
76
+ * - Standard test file patterns
77
+ * - Optimized for modern TypeScript projects
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { createJestConfig } from '@jmlweb/jest-config';
82
+ *
83
+ * export default createJestConfig({
84
+ * testEnvironment: 'jsdom',
85
+ * setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
86
+ * });
87
+ * ```
88
+ */
89
+ declare const createJestConfig: (options?: JestConfigOptions) => Config;
90
+ /**
91
+ * Base Jest configuration with TypeScript support, coverage settings, and sensible defaults.
92
+ * This configuration provides a solid foundation for testing TypeScript projects.
93
+ *
94
+ * Features:
95
+ * - TypeScript support via ts-jest
96
+ * - Coverage configuration with 80% thresholds
97
+ * - Node.js environment by default
98
+ * - Standard test file patterns
99
+ * - Optimized for modern TypeScript projects
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import jestConfig from '@jmlweb/jest-config';
104
+ *
105
+ * export default jestConfig;
106
+ * ```
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * import jestConfig from '@jmlweb/jest-config';
111
+ *
112
+ * export default {
113
+ * ...jestConfig,
114
+ * testEnvironment: 'jsdom',
115
+ * setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
116
+ * };
117
+ * ```
118
+ */
119
+ declare const config: Config;
120
+
121
+ export { type JestConfigOptions, createJestConfig, config as default };
@@ -0,0 +1,121 @@
1
+ import { Config } from 'jest';
2
+
3
+ /**
4
+ * Options for creating a Jest configuration
5
+ */
6
+ interface JestConfigOptions {
7
+ /**
8
+ * Test environment (node, jsdom, etc.)
9
+ * @default 'node'
10
+ */
11
+ testEnvironment?: 'node' | 'jsdom' | string;
12
+ /**
13
+ * Array of file extensions Jest will look for
14
+ * @default ['ts', 'tsx', 'js', 'jsx']
15
+ */
16
+ moduleFileExtensions?: string[];
17
+ /**
18
+ * Array of file patterns for test files
19
+ * @default ['**\/*.{test,spec}.{ts,tsx,js,jsx}']
20
+ */
21
+ testMatch?: string[];
22
+ /**
23
+ * Array of patterns to skip when looking for test files
24
+ * @default ['**\/node_modules\/**', '**\/dist\/**', '**\/build\/**']
25
+ */
26
+ testPathIgnorePatterns?: string[];
27
+ /**
28
+ * Coverage thresholds
29
+ * @default { global: { lines: 80, functions: 80, branches: 80, statements: 80 } }
30
+ */
31
+ coverageThreshold?: Config['coverageThreshold'];
32
+ /**
33
+ * Array of patterns to include in coverage
34
+ * @default ['src\/**\/*.{ts,tsx,js,jsx}']
35
+ */
36
+ collectCoverageFrom?: string[];
37
+ /**
38
+ * Array of patterns to exclude from coverage
39
+ * @default ['**\/*.d.ts', '**\/*.config.{ts,js}', '**\/dist\/**', '**\/build\/**', '**\/node_modules\/**', '**\/coverage\/**', '**\/*.test.{ts,tsx,js,jsx}', '**\/*.spec.{ts,tsx,js,jsx}']
40
+ */
41
+ coveragePathIgnorePatterns?: string[];
42
+ /**
43
+ * Array of reporters for coverage
44
+ * @default ['text', 'json', 'html']
45
+ */
46
+ coverageReporters?: Config['coverageReporters'];
47
+ /**
48
+ * Array of setup files to run before each test file
49
+ * @default []
50
+ */
51
+ setupFilesAfterEnv?: string[];
52
+ /**
53
+ * Module name mapper for path aliases
54
+ * @default {}
55
+ */
56
+ moduleNameMapper?: Record<string, string | string[]>;
57
+ /**
58
+ * Transform configuration
59
+ * @default { '^.+\\.tsx?$': ['ts-jest', { tsconfig: { esModuleInterop: true, allowSyntheticDefaultImports: true } }] }
60
+ */
61
+ transform?: Record<string, string | [string, Record<string, unknown>]>;
62
+ /**
63
+ * Test timeout in milliseconds
64
+ * @default 5000
65
+ */
66
+ testTimeout?: number;
67
+ }
68
+ /**
69
+ * Creates a Jest configuration with TypeScript support, coverage settings, and sensible defaults.
70
+ * This configuration provides a solid foundation for testing TypeScript projects.
71
+ *
72
+ * Features:
73
+ * - TypeScript support via ts-jest
74
+ * - Coverage configuration with 80% thresholds
75
+ * - Node.js environment by default
76
+ * - Standard test file patterns
77
+ * - Optimized for modern TypeScript projects
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { createJestConfig } from '@jmlweb/jest-config';
82
+ *
83
+ * export default createJestConfig({
84
+ * testEnvironment: 'jsdom',
85
+ * setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
86
+ * });
87
+ * ```
88
+ */
89
+ declare const createJestConfig: (options?: JestConfigOptions) => Config;
90
+ /**
91
+ * Base Jest configuration with TypeScript support, coverage settings, and sensible defaults.
92
+ * This configuration provides a solid foundation for testing TypeScript projects.
93
+ *
94
+ * Features:
95
+ * - TypeScript support via ts-jest
96
+ * - Coverage configuration with 80% thresholds
97
+ * - Node.js environment by default
98
+ * - Standard test file patterns
99
+ * - Optimized for modern TypeScript projects
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import jestConfig from '@jmlweb/jest-config';
104
+ *
105
+ * export default jestConfig;
106
+ * ```
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * import jestConfig from '@jmlweb/jest-config';
111
+ *
112
+ * export default {
113
+ * ...jestConfig,
114
+ * testEnvironment: 'jsdom',
115
+ * setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
116
+ * };
117
+ * ```
118
+ */
119
+ declare const config: Config;
120
+
121
+ export { type JestConfigOptions, createJestConfig, config as default };
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
1
+ // src/index.ts
2
+ var createJestConfig = (options = {}) => {
3
+ const {
4
+ testEnvironment = "node",
5
+ moduleFileExtensions = ["ts", "tsx", "js", "jsx", "json"],
6
+ testMatch = ["**/*.{test,spec}.{ts,tsx,js,jsx}"],
7
+ testPathIgnorePatterns = [
8
+ "/node_modules/",
9
+ "/dist/",
10
+ "/build/",
11
+ "/.git/",
12
+ "/.cache/"
13
+ ],
14
+ coverageThreshold = {
15
+ global: {
16
+ lines: 80,
17
+ functions: 80,
18
+ branches: 80,
19
+ statements: 80
20
+ }
21
+ },
22
+ collectCoverageFrom = ["src/**/*.{ts,tsx,js,jsx}"],
23
+ coveragePathIgnorePatterns = [
24
+ "/node_modules/",
25
+ "/dist/",
26
+ "/build/",
27
+ "/coverage/",
28
+ ".*\\.d\\.ts$",
29
+ ".*\\.config\\.(ts|js)$",
30
+ ".*\\.test\\.(ts|tsx|js|jsx)$",
31
+ ".*\\.spec\\.(ts|tsx|js|jsx)$"
32
+ ],
33
+ coverageReporters = ["text", "json", "html"],
34
+ setupFilesAfterEnv = [],
35
+ moduleNameMapper = {},
36
+ transform = {
37
+ "^.+\\.tsx?$": [
38
+ "ts-jest",
39
+ {
40
+ tsconfig: {
41
+ esModuleInterop: true,
42
+ allowSyntheticDefaultImports: true
43
+ }
44
+ }
45
+ ]
46
+ },
47
+ testTimeout = 5e3
48
+ } = options;
49
+ const config2 = {
50
+ // Test environment
51
+ testEnvironment,
52
+ // Module file extensions
53
+ moduleFileExtensions,
54
+ // Test file patterns
55
+ testMatch,
56
+ // Paths to ignore when looking for test files
57
+ testPathIgnorePatterns,
58
+ // Coverage configuration
59
+ collectCoverage: false,
60
+ // Disable by default, enable with --coverage flag
61
+ collectCoverageFrom,
62
+ coveragePathIgnorePatterns,
63
+ coverageThreshold,
64
+ coverageReporters,
65
+ // Setup files
66
+ setupFilesAfterEnv: setupFilesAfterEnv.length > 0 ? setupFilesAfterEnv : void 0,
67
+ // Module name mapping for path aliases
68
+ moduleNameMapper: Object.keys(moduleNameMapper).length > 0 ? moduleNameMapper : void 0,
69
+ // Transform configuration for TypeScript
70
+ transform,
71
+ // Test timeout
72
+ testTimeout,
73
+ // Verbose output for clearer test results
74
+ verbose: true,
75
+ // Clear mocks between tests
76
+ clearMocks: true,
77
+ // Restore mocks after each test
78
+ restoreMocks: true,
79
+ // Reset modules between tests
80
+ resetModules: false
81
+ };
82
+ Object.keys(config2).forEach((key) => {
83
+ if (config2[key] === void 0) {
84
+ delete config2[key];
85
+ }
86
+ });
87
+ return config2;
88
+ };
89
+ var config = createJestConfig();
90
+ var index_default = config;
91
+ export {
92
+ createJestConfig,
93
+ index_default as default
94
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@jmlweb/jest-config",
3
+ "version": "0.0.0",
4
+ "description": "Base Jest configuration for jmlweb projects with TypeScript support and coverage settings",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "keywords": [
27
+ "coverage",
28
+ "jest",
29
+ "jest-config",
30
+ "test-config",
31
+ "testing",
32
+ "typescript"
33
+ ],
34
+ "author": "jmlweb",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/jmlweb/tooling.git"
39
+ },
40
+ "bugs": "https://github.com/jmlweb/tooling/issues",
41
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/jest-config#readme",
42
+ "engines": {
43
+ "node": ">=20.11.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "@types/jest": ">=29.0.0",
50
+ "jest": ">=29.0.0",
51
+ "ts-jest": ">=29.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/jest": "^29.5.14",
55
+ "jest": "^29.7.0",
56
+ "ts-jest": "^29.4.6",
57
+ "tsup": "^8.5.1",
58
+ "typescript": "^5.9.3",
59
+ "@jmlweb/tsconfig-internal": "0.0.1"
60
+ },
61
+ "scripts": {
62
+ "build": "tsup",
63
+ "clean": "rm -rf dist"
64
+ }
65
+ }