jest-test-lineage-reporter 2.0.1

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/README.md ADDED
@@ -0,0 +1,822 @@
1
+ # Jest Test Lineage Reporter
2
+
3
+ **VIBE CODED
4
+ Public disclaimer: This package is vibe coded, please use at your own risk**
5
+
6
+ A comprehensive test analytics platform that provides line-by-line test coverage, performance metrics, memory analysis, test quality scoring, and mutation testing.
7
+
8
+ ## Features
9
+
10
+ - **Line-by-line coverage mapping**: See exactly which tests execute each line of your source code
11
+ - **Visual HTML reports**: Beautiful, interactive HTML reports for easy visualization
12
+ - **Test redundancy identification**: Identify multiple tests covering the same lines
13
+ - **Mutation testing**: Automated test quality assessment through code mutations
14
+ - **Performance monitoring**: CPU cycles, memory leaks, and GC pressure detection
15
+ - **Test quality scoring**: Comprehensive test quality metrics and improvement recommendations
16
+ - **Easy integration**: Simple Jest reporter that works alongside existing reporters
17
+ - **TypeScript support**: Built with TypeScript support out of the box
18
+ - **Statistics and insights**: File-level and overall statistics about test coverage patterns
19
+
20
+ ## ๐Ÿ“ฆ Installation
21
+
22
+ ### **Option 1: Install from NPM (Recommended)**
23
+
24
+ ```bash
25
+ npm install jest-test-lineage-reporter --save-dev
26
+ ```
27
+
28
+ ### **Option 2: Install from GitHub**
29
+
30
+ ```bash
31
+ # Install latest from GitHub
32
+ npm install kivancbilen/jest-test-lineage-reporter --save-dev
33
+
34
+ # Install specific version/tag
35
+ npm install kivancbilen/jest-test-lineage-reporter#v2.0.0 --save-dev
36
+
37
+ # Install from specific branch
38
+ npm install kivancbilen/jest-test-lineage-reporter#main --save-dev
39
+ ```
40
+
41
+ **Note**: Configuration paths differ slightly between NPM and GitHub installations (see setup instructions below).
42
+
43
+ ## โš™๏ธ Quick Start
44
+
45
+ ### 1. **Basic Setup**
46
+
47
+ #### **For NPM Installation:**
48
+
49
+ ```javascript
50
+ // jest.config.js
51
+ module.exports = {
52
+ // Enable coverage collection
53
+ collectCoverage: true,
54
+
55
+ // Add the reporter
56
+ reporters: [
57
+ 'default',
58
+ 'jest-test-lineage-reporter'
59
+ ],
60
+
61
+ // Enable precise test tracking
62
+ setupFilesAfterEnv: ['jest-test-lineage-reporter/src/testSetup.js'],
63
+
64
+ // Configure Babel transformation (if using TypeScript/modern JS)
65
+ transform: {
66
+ '^.+\\.(ts|tsx|js|jsx)$': 'babel-jest',
67
+ }
68
+ };
69
+ ```
70
+
71
+ #### **For GitHub Installation:**
72
+
73
+ ```javascript
74
+ // jest.config.js
75
+ module.exports = {
76
+ // Enable coverage collection
77
+ collectCoverage: true,
78
+
79
+ // Add the reporter (use relative path for GitHub install)
80
+ reporters: [
81
+ 'default',
82
+ './node_modules/jest-test-lineage-reporter/src/TestCoverageReporter.js'
83
+ ],
84
+
85
+ // Enable precise test tracking
86
+ setupFilesAfterEnv: ['./node_modules/jest-test-lineage-reporter/src/testSetup.js'],
87
+
88
+ // Configure Babel transformation (if using TypeScript/modern JS)
89
+ transform: {
90
+ '^.+\\.(ts|tsx|js|jsx)$': 'babel-jest',
91
+ }
92
+ };
93
+ ```
94
+
95
+ ### 2. **Babel Configuration**
96
+
97
+ #### **For NPM Installation:**
98
+
99
+ ```javascript
100
+ // babel.config.js
101
+ module.exports = {
102
+ presets: [
103
+ ['@babel/preset-env', { targets: { node: 'current' } }],
104
+ '@babel/preset-typescript' // If using TypeScript
105
+ ],
106
+ plugins: [
107
+ // Add the lineage tracking plugin
108
+ 'jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
109
+ ]
110
+ };
111
+ ```
112
+
113
+ #### **For GitHub Installation:**
114
+
115
+ ```javascript
116
+ // babel.config.js
117
+ module.exports = {
118
+ presets: [
119
+ ['@babel/preset-env', { targets: { node: 'current' } }],
120
+ '@babel/preset-typescript' // If using TypeScript
121
+ ],
122
+ plugins: [
123
+ // Add the lineage tracking plugin (use full path for GitHub install)
124
+ './node_modules/jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
125
+ ]
126
+ };
127
+ ```
128
+
129
+ ### 3. **Install Required Dependencies**
130
+
131
+ If you don't have Babel setup already:
132
+
133
+ ```bash
134
+ npm install --save-dev @babel/core @babel/preset-env babel-jest
135
+ # For TypeScript projects, also install:
136
+ npm install --save-dev @babel/preset-typescript
137
+ ```
138
+
139
+ ### 4. **Run Tests**
140
+
141
+ ```bash
142
+ npm test
143
+ ```
144
+
145
+ ### 5. **View Results**
146
+
147
+ Open the generated report:
148
+
149
+ ```bash
150
+ # macOS/Linux
151
+ open test-lineage-report.html
152
+
153
+ # Windows
154
+ start test-lineage-report.html
155
+ ```
156
+
157
+ ## ๐Ÿ“Š What You'll Get
158
+
159
+ The reporter generates:
160
+ 1. **๐Ÿ“‹ Console Report**: Detailed analytics in your terminal
161
+ 2. **๐ŸŒ Interactive HTML Dashboard**: Beautiful visual report with 5 views
162
+ 3. **๐Ÿ“ˆ Performance Insights**: Memory leaks, GC pressure, slow tests
163
+ 4. **๐Ÿงช Quality Metrics**: Test quality scores and improvement recommendations
164
+ 5. **๐Ÿงฌ Mutation Testing**: Automated test effectiveness validation
165
+
166
+ ## ๐Ÿ”ง How It Works
167
+
168
+ Jest Test Lineage Reporter uses a sophisticated multi-layered approach to provide precise test analytics:
169
+
170
+ ### **1. ๐Ÿ”„ Babel Plugin Transformation**
171
+
172
+ The **Babel plugin** (`babel-plugin-lineage-tracker.js`) is the core of the system:
173
+
174
+ ```javascript
175
+ // Your original code:
176
+ function add(a, b) {
177
+ return a + b;
178
+ }
179
+
180
+ // Gets transformed to:
181
+ function add(a, b) {
182
+ global.__TEST_LINEAGE_TRACKER__.trackExecution('src/calculator.js', 2, 1);
183
+ return a + b;
184
+ }
185
+ ```
186
+
187
+ **What the plugin does:**
188
+ - ๐ŸŽฏ **Injects tracking calls** into every line of your source code
189
+ - ๐Ÿ“ **Records exact line numbers** and file paths
190
+ - ๐Ÿ”ข **Tracks call depth** (how deep in the function call stack)
191
+ - โšก **Minimal overhead** - only active during testing
192
+
193
+ ### **2. ๐Ÿงช Test Setup Integration**
194
+
195
+ The **test setup file** (`testSetup.js`) provides:
196
+
197
+ ```javascript
198
+ // Tracks which test is currently running
199
+ global.__TEST_LINEAGE_TRACKER__ = {
200
+ currentTest: null,
201
+ testCoverage: new Map(),
202
+ isTracking: false
203
+ };
204
+ ```
205
+
206
+ **Key features:**
207
+ - ๐ŸŽฏ **Per-test isolation** - knows exactly which test is executing
208
+ - ๐Ÿ“Š **Performance monitoring** - CPU cycles, memory usage, GC pressure
209
+ - ๐Ÿงช **Test quality analysis** - assertion counting, test smell detection
210
+ - ๐Ÿ” **Call depth tracking** - maps function call chains
211
+
212
+ ### **3. ๐Ÿ“ˆ Jest Reporter Integration**
213
+
214
+ The **main reporter** (`TestCoverageReporter.js`) processes all collected data:
215
+
216
+ **Data Collection:**
217
+ - โœ… Aggregates tracking data from all tests
218
+ - โœ… Correlates line executions with specific tests
219
+ - โœ… Calculates performance metrics and quality scores
220
+ - โœ… Generates comprehensive analytics
221
+
222
+ **Output Generation:**
223
+ - ๐Ÿ“‹ **Console reports** with real-time alerts
224
+ - ๐ŸŒ **Interactive HTML dashboard** with 4 different views
225
+ - ๐Ÿ“Š **Sortable data tables** with 11+ sorting options
226
+ - ๐Ÿšจ **Visual alerts** for performance issues
227
+
228
+ ### **4. ๐ŸŽฏ Precision Tracking System**
229
+
230
+ **Line-by-Line Accuracy:**
231
+ ```javascript
232
+ // Each line gets unique tracking:
233
+ Line 1: trackExecution('file.js', 1, depth) // Function declaration
234
+ Line 2: trackExecution('file.js', 2, depth) // Variable assignment
235
+ Line 3: trackExecution('file.js', 3, depth) // Return statement
236
+ ```
237
+
238
+ **Call Depth Analysis:**
239
+ ```javascript
240
+ function outer() { // Depth 1 (D1)
241
+ return inner(); // Depth 1 โ†’ calls inner
242
+ }
243
+
244
+ function inner() { // Depth 2 (D2)
245
+ return deepFunction(); // Depth 2 โ†’ calls deep
246
+ }
247
+
248
+ function deepFunction() { // Depth 3 (D3)
249
+ return 42; // Depth 3
250
+ }
251
+ ```
252
+
253
+ ### **5. ๐Ÿ”ฅ Performance Monitoring**
254
+
255
+ **Real-time Performance Tracking:**
256
+ - **๐Ÿšจ Memory Leaks**: Detects allocations >50KB per test
257
+ - **๐Ÿ—‘๏ธ GC Pressure**: Monitors garbage collection frequency
258
+ - **๐ŸŒ Slow Tests**: Identifies performance outliers
259
+ - **โšก CPU Cycles**: Hardware-level performance measurement
260
+
261
+ **Quality Analysis:**
262
+ - **๐Ÿ“Š Assertion Counting**: Tracks test thoroughness
263
+ - **๐Ÿงช Test Smell Detection**: Identifies problematic patterns
264
+ - **๐Ÿ” Error Handling**: Measures test robustness
265
+ - **๐Ÿ“ˆ Maintainability Scoring**: 0-100% quality metrics
266
+
267
+ ### **6. ๐ŸŽจ Data Visualization**
268
+
269
+ **Interactive HTML Dashboard:**
270
+ - **๐Ÿ“ Files View**: Expandable source code with coverage highlights
271
+ - **๐Ÿ“Š Lines Analysis**: Sortable table with all metrics
272
+ - **๐Ÿ”ฅ Performance Analytics**: CPU, memory, and performance hotspots
273
+ - **๐Ÿงช Test Quality**: Quality scores, test smells, and recommendations
274
+ - **๐Ÿงฌ Mutation Testing**: Mutation scores, survived/killed mutations, and test effectiveness
275
+
276
+ **Real-time Alerts:**
277
+ ```bash
278
+ Line 21: "heavyFunction" (performance-example.ts, 80,000 executions,
279
+ depths 1,4, 571 cycles, 0.2ฮผs, +5.4MB ๐ŸšจLEAK ๐ŸŒSLOW) โœ… PRECISE
280
+ ```
281
+
282
+ This multi-layered approach provides **unprecedented visibility** into your test suite's behavior, performance, and quality!
283
+
284
+ ## ๐Ÿงฌ Mutation Testing
285
+
286
+ Jest Test Lineage Reporter includes **automated mutation testing** to validate the effectiveness of your test suite by introducing small code changes (mutations) and checking if your tests catch them.
287
+
288
+ ### **What is Mutation Testing?**
289
+
290
+ Mutation testing works by:
291
+ 1. **๐Ÿ”„ Creating mutations**: Small changes to your source code (e.g., changing `+` to `-`, `>` to `<`)
292
+ 2. **๐Ÿงช Running tests**: Execute your test suite against each mutation
293
+ 3. **๐Ÿ“Š Measuring effectiveness**: Count how many mutations your tests catch (kill) vs miss (survive)
294
+
295
+ ### **How It Works**
296
+
297
+ ```javascript
298
+ // Original code:
299
+ function add(a, b) {
300
+ return a + b; // Line 2
301
+ }
302
+
303
+ // Mutation 1: Arithmetic operator
304
+ function add(a, b) {
305
+ return a - b; // Changed + to -
306
+ }
307
+
308
+ // Mutation 2: Comparison operator
309
+ function add(a, b) {
310
+ return a > b; // Changed + to >
311
+ }
312
+ ```
313
+
314
+ **Smart Test Selection**: Only runs tests that actually cover the mutated line, making mutation testing fast and efficient.
315
+
316
+ ### **Mutation Types Supported**
317
+
318
+ - **๐Ÿ”ข Arithmetic**: `+`, `-`, `*`, `/`, `%` operators
319
+ - **๐Ÿ” Comparison**: `>`, `<`, `>=`, `<=`, `==`, `!=` operators
320
+ - **๐Ÿง  Logical**: `&&`, `||`, `!` operators
321
+ - **๐Ÿ”„ Conditional**: `if`, `while`, `for` conditions
322
+ - **๐Ÿ“ Literals**: `true`/`false`, numbers, strings
323
+ - **โ†ฉ๏ธ Returns**: Return values and statements
324
+ - **โž• Increments**: `++`, `--` operators
325
+ - **๐Ÿ“‹ Assignment**: `+=`, `-=`, `*=`, `/=` operators
326
+
327
+ ### **Mutation Testing Results**
328
+
329
+ The HTML report includes a dedicated **Mutations View** showing:
330
+
331
+ ```
332
+ ๐Ÿงฌ Mutation Testing Results
333
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
334
+ โ”‚ ๐Ÿ“Š Overall Score: 85% (17/20 mutations killed) โ”‚
335
+ โ”‚ โœ… Killed: 17 ๐Ÿ”ด Survived: 3 โŒ Errors: 0 โ”‚
336
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
337
+
338
+ ๐Ÿ“ src/calculator.ts
339
+ โ”œโ”€โ”€ Line 5: add function
340
+ โ”‚ โœ… Killed: + โ†’ - (caught by "should add numbers")
341
+ โ”‚ โœ… Killed: + โ†’ * (caught by "should add numbers")
342
+ โ”‚ ๐Ÿ”ด Survived: + โ†’ 0 (no test caught this!)
343
+ โ”‚
344
+ โ””โ”€โ”€ Line 12: multiply function
345
+ โœ… Killed: * โ†’ + (caught by "should multiply")
346
+ ๐Ÿ”ด Survived: * โ†’ / (tests missed this change)
347
+ ```
348
+
349
+ ### **Interpreting Results**
350
+
351
+ - **๐ŸŽฏ High Score (80%+)**: Excellent test coverage and quality
352
+ - **โš ๏ธ Medium Score (60-80%)**: Good coverage, some gaps to address
353
+ - **๐Ÿšจ Low Score (<60%)**: Significant testing gaps, needs improvement
354
+
355
+ **Survived Mutations** indicate:
356
+ - Missing test cases for edge conditions
357
+ - Weak assertions that don't verify specific behavior
358
+ - Logic paths not covered by tests
359
+
360
+ ### **Configuration**
361
+
362
+ Mutation testing runs automatically after regular tests complete. Configure it in your Jest config:
363
+
364
+ ```javascript
365
+ // jest.config.js
366
+ module.exports = {
367
+ reporters: [
368
+ 'default',
369
+ ['jest-test-lineage-reporter', {
370
+ // Mutation testing settings
371
+ enableMutationTesting: true, // Enable/disable mutation testing
372
+ mutationTimeout: 10000, // Max time per mutation (ms)
373
+ mutationThreshold: 0.8, // Minimum score to pass (80%)
374
+ maxMutationsPerFile: 50, // Limit mutations per file
375
+
376
+ // Mutation types to enable
377
+ enabledMutations: [
378
+ 'arithmetic', // +, -, *, /, %
379
+ 'comparison', // >, <, >=, <=, ==, !=
380
+ 'logical', // &&, ||, !
381
+ 'conditional', // if/while/for conditions
382
+ 'literals', // true/false, numbers
383
+ 'returns', // return statements
384
+ 'increments', // ++, --
385
+ 'assignment' // +=, -=, *=, /=
386
+ ]
387
+ }]
388
+ ]
389
+ };
390
+ ```
391
+
392
+ ### **Performance Optimization**
393
+
394
+ Mutation testing is optimized for speed:
395
+ - **๐ŸŽฏ Smart targeting**: Only tests covering mutated lines are executed
396
+ - **โšก Parallel execution**: Multiple mutations tested simultaneously
397
+ - **๐Ÿšซ Early termination**: Stops when first test fails (mutation killed)
398
+ - **๐Ÿ“Š Incremental**: Caches results for unchanged code
399
+
400
+ ### **Best Practices**
401
+
402
+ 1. **Start small**: Enable mutation testing on critical files first
403
+ 2. **Set realistic thresholds**: Begin with 70% score, improve over time
404
+ 3. **Focus on survivors**: Prioritize fixing survived mutations
405
+ 4. **Use with coverage**: Combine with line coverage for complete picture
406
+ 5. **CI integration**: Run mutation testing in dedicated CI jobs
407
+
408
+ ## Example Output
409
+
410
+ ### Console Output
411
+ ```
412
+ --- Jest Test Lineage Reporter: Line-by-Line Test Coverage ---
413
+
414
+ ๐Ÿ“„ File: /path/to/your/src/calculator.ts
415
+ Line 2: Covered by 4 test(s)
416
+ - "Calculator should correctly add two numbers"
417
+ - "Calculator should subtract a smaller number from a larger one"
418
+ - "Calculator should subtract a larger number from a smaller one and return a positive result"
419
+ - "Calculator should handle zero correctly in subtraction"
420
+ Line 7: Covered by 3 test(s)
421
+ - "Calculator should subtract a smaller number from a larger one"
422
+ - "Calculator should subtract a larger number from a smaller one and return a positive result"
423
+ - "Calculator should handle zero correctly in subtraction"
424
+
425
+ --- Report End ---
426
+
427
+ ๐Ÿ“„ Generating HTML coverage report...
428
+ โœ… HTML report generated: /path/to/your/project/test-lineage-report.html
429
+ ๐ŸŒ Open the file in your browser to view the visual coverage report
430
+
431
+ ๐Ÿงฌ Running mutation testing...
432
+ ๐Ÿ“Š Mutation testing completed: 85% score (17/20 mutations killed)
433
+ ๐Ÿ”ด 3 mutations survived - check the Mutations view in the HTML report
434
+ ```
435
+
436
+ ### HTML Report
437
+ The HTML report provides a beautiful, interactive dashboard with 5 specialized views:
438
+
439
+ #### **๐Ÿ“ Files View**
440
+ - **Complete source code display** with syntax highlighting and line numbers
441
+ - **Visual coverage indicators** showing covered (green) vs uncovered (red) lines
442
+ - **Interactive line-by-line exploration** - click coverage indicators to expand/collapse test details
443
+ - **Test grouping by file** showing which test files cover each line
444
+
445
+ #### **๐Ÿ“Š Lines Analysis View**
446
+ - **Sortable data table** with 11+ sorting options (executions, tests, depth, performance, quality)
447
+ - **Quality metrics** including test smells with hover tooltips showing specific smell types
448
+ - **Performance data** including CPU cycles, memory usage, and execution times
449
+ - **Call depth information** showing function call chain depths
450
+
451
+ #### **๐Ÿ”ฅ Performance Analytics View**
452
+ - **Memory leak detection** with detailed allocation tracking
453
+ - **GC pressure monitoring** showing garbage collection stress
454
+ - **CPU performance metrics** with cycle counts and timing data
455
+ - **Performance alerts** highlighting slow tests and memory issues
456
+
457
+ #### **๐Ÿงช Test Quality View**
458
+ - **Quality scoring dashboard** with maintainability and reliability metrics
459
+ - **Test smell analysis** showing specific issues like "Weak Assertions", "Long Test", etc.
460
+ - **Improvement recommendations** with actionable suggestions
461
+ - **Quality distribution charts** showing high/good/fair/poor quality breakdown
462
+
463
+ #### **๐Ÿงฌ Mutation Testing View**
464
+ - **Mutation score dashboard** showing overall test effectiveness
465
+ - **Detailed mutation results** with killed/survived/error breakdowns
466
+ - **File-by-file analysis** showing which mutations were caught by tests
467
+ - **Survival analysis** highlighting gaps in test coverage
468
+
469
+ **Additional Features:**
470
+ - **Hover effects and tooltips** for enhanced user experience
471
+ - **File-level statistics** showing total lines, covered lines, and unique tests
472
+ - **Modern, responsive design** that works on all devices
473
+ - **Interactive controls** for sorting, filtering, and exploring data
474
+
475
+ ## โš™๏ธ Configuration Options
476
+
477
+ ### **Basic Configuration**
478
+
479
+ ```javascript
480
+ // jest.config.js
481
+ module.exports = {
482
+ reporters: [
483
+ 'default',
484
+ ['jest-test-lineage-reporter', {
485
+ outputFile: 'my-test-report.html',
486
+ memoryLeakThreshold: 100 * 1024, // 100KB
487
+ qualityThreshold: 70
488
+ }]
489
+ ],
490
+ setupFilesAfterEnv: ['jest-test-lineage-reporter/src/testSetup.js'],
491
+ collectCoverage: true,
492
+ collectCoverageFrom: [
493
+ 'src/**/*.{js,ts,jsx,tsx}',
494
+ '!src/**/*.d.ts'
495
+ ]
496
+ };
497
+ ```
498
+
499
+ ### **Advanced Configuration**
500
+
501
+ ```javascript
502
+ // jest.config.js
503
+ module.exports = {
504
+ reporters: [
505
+ 'default',
506
+ ['jest-test-lineage-reporter', {
507
+ // Output settings
508
+ outputFile: 'test-analytics-report.html',
509
+ enableConsoleOutput: true,
510
+ enableDebugLogging: false,
511
+
512
+ // Performance thresholds
513
+ memoryLeakThreshold: 50 * 1024, // 50KB - triggers ๐ŸšจLEAK alerts
514
+ gcPressureThreshold: 5, // Number of allocations - triggers ๐Ÿ—‘๏ธGC alerts
515
+ slowExecutionThreshold: 2.0, // Multiplier for slow tests - triggers ๐ŸŒSLOW alerts
516
+
517
+ // Quality thresholds
518
+ qualityThreshold: 60, // Minimum quality score (0-100%)
519
+ reliabilityThreshold: 60, // Minimum reliability score
520
+ maintainabilityThreshold: 60, // Minimum maintainability score
521
+ maxTestSmells: 2, // Maximum test smells before flagging
522
+
523
+ // Feature toggles
524
+ enableCpuCycleTracking: true, // Hardware-level performance tracking
525
+ enableMemoryTracking: true, // Memory leak detection
526
+ enableCallDepthTracking: true, // Function call depth analysis
527
+ enableInteractiveFeatures: true, // Interactive HTML dashboard
528
+ enableMutationTesting: true, // Automated mutation testing
529
+
530
+ // Mutation testing settings
531
+ mutationTimeout: 10000, // Max time per mutation (ms)
532
+ mutationThreshold: 0.8, // Minimum score to pass (80%)
533
+ maxMutationsPerFile: 50, // Limit mutations per file
534
+ enabledMutations: ['arithmetic', 'comparison', 'logical'], // Mutation types
535
+
536
+ // File filtering
537
+ includePatterns: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
538
+ excludePatterns: ['**/node_modules/**', '**/dist/**', '**/build/**']
539
+ }]
540
+ ],
541
+ setupFilesAfterEnv: ['jest-test-lineage-reporter/src/testSetup.js'],
542
+ collectCoverage: true,
543
+ collectCoverageFrom: [
544
+ 'src/**/*.{js,ts,jsx,tsx}',
545
+ '!src/**/*.d.ts'
546
+ ]
547
+ };
548
+ ```
549
+
550
+ ### **Environment Variables**
551
+
552
+ You can also configure via environment variables:
553
+
554
+ ```bash
555
+ # ๐ŸŽ›๏ธ FEATURE TOGGLES (Master Controls)
556
+ export JEST_LINEAGE_ENABLED=true # Master switch (default: true)
557
+ export JEST_LINEAGE_TRACKING=true # Line-by-line tracking (default: true)
558
+ export JEST_LINEAGE_PERFORMANCE=true # Performance monitoring (default: true)
559
+ export JEST_LINEAGE_QUALITY=true # Quality analysis (default: true)
560
+ export JEST_LINEAGE_MUTATION=true # Mutation testing (default: false)
561
+
562
+ # ๐Ÿ“ OUTPUT SETTINGS
563
+ export JEST_LINEAGE_OUTPUT_FILE=custom-report.html
564
+ export JEST_LINEAGE_DEBUG=true
565
+
566
+ # ๐ŸŽฏ PERFORMANCE THRESHOLDS
567
+ export JEST_LINEAGE_MEMORY_THRESHOLD=100000 # 100KB
568
+ export JEST_LINEAGE_GC_THRESHOLD=10
569
+ export JEST_LINEAGE_QUALITY_THRESHOLD=70
570
+
571
+ # ๐Ÿงฌ MUTATION TESTING SETTINGS
572
+ export JEST_LINEAGE_MUTATION_TIMEOUT=10000 # 10 seconds per mutation
573
+ export JEST_LINEAGE_MUTATION_THRESHOLD=80 # 80% minimum score
574
+ export JEST_LINEAGE_MAX_MUTATIONS=50 # Max mutations per file
575
+ ```
576
+
577
+ ## ๐ŸŽ›๏ธ **Enable/Disable Controls**
578
+
579
+ ### **Quick Disable/Enable**
580
+
581
+ ```bash
582
+ # ๐Ÿšซ COMPLETELY DISABLE (fastest - no instrumentation)
583
+ export JEST_LINEAGE_ENABLED=false
584
+ npm test
585
+
586
+ # โœ… RE-ENABLE
587
+ export JEST_LINEAGE_ENABLED=true
588
+ npm test
589
+
590
+ # ๐ŸŽฏ SELECTIVE DISABLE (keep basic tracking, disable heavy features)
591
+ export JEST_LINEAGE_PERFORMANCE=false # Disable CPU/memory monitoring
592
+ export JEST_LINEAGE_QUALITY=false # Disable test quality analysis
593
+ export JEST_LINEAGE_MUTATION=false # Disable mutation testing
594
+ npm test
595
+ ```
596
+
597
+ ### **Configuration-Based Control**
598
+
599
+ ```javascript
600
+ // jest.config.js - Conditional setup
601
+ const enableLineage = process.env.NODE_ENV !== 'production';
602
+
603
+ module.exports = {
604
+ reporters: [
605
+ 'default',
606
+ ...(enableLineage ? ['jest-test-lineage-reporter'] : [])
607
+ ],
608
+ setupFilesAfterEnv: [
609
+ ...(enableLineage ? ['jest-test-lineage-reporter/src/testSetup.js'] : [])
610
+ ]
611
+ };
612
+ ```
613
+
614
+ ### **Babel Plugin Control**
615
+
616
+ ```javascript
617
+ // babel.config.js - Conditional instrumentation
618
+ const enableLineage = process.env.JEST_LINEAGE_ENABLED !== 'false';
619
+
620
+ module.exports = {
621
+ presets: [
622
+ ['@babel/preset-env', { targets: { node: 'current' } }]
623
+ ],
624
+ plugins: [
625
+ // Only add plugin when enabled
626
+ ...(enableLineage ? [
627
+ ['jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js', {
628
+ enabled: true
629
+ }]
630
+ ] : [])
631
+ ]
632
+ };
633
+ ```
634
+
635
+ ### **Use Cases for Disabling**
636
+
637
+ #### **๐Ÿš€ CI/CD Pipelines**
638
+ ```bash
639
+ # Fast CI runs - disable detailed tracking
640
+ export JEST_LINEAGE_ENABLED=false
641
+ npm test
642
+
643
+ # Detailed analysis runs - enable everything
644
+ export JEST_LINEAGE_ENABLED=true
645
+ npm test
646
+ ```
647
+
648
+ #### **๐Ÿ”ง Development Workflow**
649
+ ```bash
650
+ # Quick development testing
651
+ export JEST_LINEAGE_PERFORMANCE=false
652
+ npm test
653
+
654
+ # Deep analysis when needed
655
+ export JEST_LINEAGE_PERFORMANCE=true
656
+ npm test
657
+ ```
658
+
659
+ #### **๐Ÿ“Š Performance Testing**
660
+ ```bash
661
+ # Measure test performance without instrumentation overhead
662
+ export JEST_LINEAGE_ENABLED=false
663
+ npm test
664
+
665
+ # Analyze test quality and performance
666
+ export JEST_LINEAGE_ENABLED=true
667
+ npm test
668
+ ```
669
+
670
+ ### **๐Ÿ“ฆ NPM Scripts (For Package Development)**
671
+
672
+ If you're working on the jest-test-lineage-reporter package itself, you can use these scripts:
673
+
674
+ ```bash
675
+ # ๐Ÿš€ Fast testing (no instrumentation)
676
+ npm run test:fast
677
+
678
+ # ๐Ÿ“Š Full lineage analysis
679
+ npm run test:lineage
680
+
681
+ # ๐Ÿ”ฅ Performance focus (no quality analysis)
682
+ npm run test:performance
683
+
684
+ # ๐Ÿงช Quality focus (no performance monitoring)
685
+ npm run test:quality
686
+
687
+ # ๐Ÿงฌ Mutation testing focus
688
+ npm run test:mutation
689
+
690
+ # ๐Ÿ‘€ Watch mode with lineage
691
+ npm run test:watch
692
+ ```
693
+
694
+ ## How It Works
695
+
696
+ 1. **Coverage Collection**: Jest collects Istanbul coverage data during test execution
697
+ 2. **Test Result Processing**: The reporter hooks into Jest's `onTestResult` event to capture both test results and coverage data
698
+ 3. **Line Mapping**: For each covered line, the reporter associates it with all successful tests from the test file that executed it
699
+ 4. **Report Generation**: After all tests complete, the reporter generates a comprehensive line-by-line breakdown
700
+
701
+ ## Limitations
702
+
703
+ Due to Jest's architecture, this reporter has one important limitation:
704
+
705
+ - **File-level granularity**: The reporter associates all successful tests in a test file with all lines covered during that file's execution. It cannot determine which specific `it()` block covered which line.
706
+
707
+ For a truly perfect solution that maps individual test cases to specific lines, you would need:
708
+ 1. To run each test in isolation (very slow)
709
+ 2. Deep integration with Jest's internals and V8/Istanbul instrumentation
710
+
711
+ However, this reporter provides significant value for understanding test coverage patterns and identifying potential redundancies at the file level.
712
+
713
+ ## Project Structure
714
+
715
+ ```
716
+ jest-test-lineage-reporter/
717
+ โ”œโ”€โ”€ src/
718
+ โ”‚ โ”œโ”€โ”€ __tests__/
719
+ โ”‚ โ”‚ โ””โ”€โ”€ calculator.test.ts # Example test file
720
+ โ”‚ โ”œโ”€โ”€ calculator.ts # Example source file
721
+ โ”‚ โ”œโ”€โ”€ TestCoverageReporter.js # Main reporter implementation
722
+ โ”‚ โ””โ”€โ”€ TestCoverageReporter.ts # TypeScript version (reference)
723
+ โ”œโ”€โ”€ jest.config.js # Jest configuration
724
+ โ”œโ”€โ”€ package.json # Project dependencies
725
+ โ”œโ”€โ”€ tsconfig.json # TypeScript configuration
726
+ โ””โ”€โ”€ README.md # This file
727
+ ```
728
+
729
+ ## ๐Ÿ”ง Troubleshooting
730
+
731
+ ### **Common Issues**
732
+
733
+ #### **"Cannot find module" Error**
734
+ ```bash
735
+ Error: Cannot find module 'jest-test-lineage-reporter/src/testSetup.js'
736
+ ```
737
+ **Solutions**:
738
+ 1. **Make sure the package is installed**:
739
+ ```bash
740
+ npm install jest-test-lineage-reporter --save-dev
741
+ ```
742
+
743
+ 2. **Use the correct path in jest.config.js**:
744
+ ```javascript
745
+ // โœ… Correct - short path (recommended)
746
+ setupFilesAfterEnv: ['jest-test-lineage-reporter/src/testSetup.js']
747
+
748
+ // โœ… Also correct - explicit path
749
+ setupFilesAfterEnv: ['./node_modules/jest-test-lineage-reporter/src/testSetup.js']
750
+ ```
751
+
752
+ 3. **For Babel plugin in babel.config.js**:
753
+ ```javascript
754
+ plugins: [
755
+ // โœ… Recommended - short path
756
+ 'jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
757
+
758
+ // โœ… Also works - explicit path
759
+ // './node_modules/jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
760
+ ]
761
+ ```
762
+
763
+ #### **No HTML Report Generated**
764
+ **Possible causes**:
765
+ - Tests failed before completion
766
+ - No coverage data collected
767
+ - File permissions issue
768
+
769
+ **Solution**:
770
+ 1. Ensure `collectCoverage: true` is set
771
+ 2. Check that tests are passing
772
+ 3. Verify write permissions in the project directory
773
+
774
+ #### **Performance Tracking Not Working**
775
+ **Solution**: Make sure Babel plugin is configured:
776
+ ```javascript
777
+ // babel.config.js
778
+ module.exports = {
779
+ plugins: [
780
+ './node_modules/jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
781
+ ]
782
+ };
783
+ ```
784
+
785
+ #### **TypeScript Issues**
786
+ **Solution**: Install TypeScript preset:
787
+ ```bash
788
+ npm install --save-dev @babel/preset-typescript
789
+ ```
790
+
791
+ ### **Getting Help**
792
+
793
+ - ๐Ÿ“– **Documentation**: Check the examples in `/src/__tests__/`
794
+ - ๐Ÿ› **Issues**: [GitHub Issues](https://github.com/kivancbilen/jest-test-lineage-reporter/issues)
795
+ - ๐Ÿ’ฌ **Discussions**: [GitHub Discussions](https://github.com/kivancbilen/jest-test-lineage-reporter/discussions)
796
+
797
+ ## ๐Ÿ†˜ Requirements
798
+
799
+ - **Jest**: 24.0.0 or higher
800
+ - **Node.js**: 14.0.0 or higher
801
+ - **Babel**: 7.0.0 or higher (for advanced features)
802
+
803
+ ## ๐Ÿค Contributing
804
+
805
+ 1. Fork the repository
806
+ 2. Create a feature branch: `git checkout -b feature/amazing-feature`
807
+ 3. Make your changes
808
+ 4. Add tests for new functionality
809
+ 5. Ensure all tests pass: `npm test`
810
+ 6. Commit your changes: `git commit -m 'Add amazing feature'`
811
+ 7. Push to the branch: `git push origin feature/amazing-feature`
812
+ 8. Open a Pull Request
813
+
814
+ ## ๐Ÿ“„ License
815
+
816
+ MIT License - see [LICENSE](LICENSE) file for details.
817
+
818
+ ## ๐Ÿ™ Acknowledgments
819
+
820
+ - Jest team for the excellent testing framework
821
+ - Istanbul for coverage instrumentation
822
+ - The open-source community for inspiration and feedback