jest-test-lineage-reporter 2.0.1 → 2.1.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.
Files changed (34) hide show
  1. package/README.md +252 -0
  2. package/bin/jest-lineage.js +20 -0
  3. package/package.json +14 -5
  4. package/src/MutationTester.js +1154 -0
  5. package/src/__tests__/assertion-test.test.ts +59 -0
  6. package/src/__tests__/calculator.test.ts +30 -0
  7. package/src/__tests__/depth-example.test.ts +237 -0
  8. package/src/__tests__/gc-pressure-example.test.ts +169 -0
  9. package/src/__tests__/performance-example.test.ts +83 -0
  10. package/src/__tests__/quality-example.test.ts +122 -0
  11. package/src/__tests__/survived-mutations-example.test.ts +32 -0
  12. package/src/__tests__/truly-weak-example.test.ts +90 -0
  13. package/src/__tests__/weak-test-example.test.ts +222 -0
  14. package/src/babel-plugin-mutation-tester.js +402 -0
  15. package/src/calculator.ts +12 -0
  16. package/src/cli/commands/analyze.js +91 -0
  17. package/src/cli/commands/mutate.js +89 -0
  18. package/src/cli/commands/query.js +107 -0
  19. package/src/cli/commands/report.js +65 -0
  20. package/src/cli/commands/test.js +56 -0
  21. package/src/cli/index.js +89 -0
  22. package/src/cli/utils/config-loader.js +114 -0
  23. package/src/cli/utils/data-loader.js +118 -0
  24. package/src/cli/utils/jest-runner.js +105 -0
  25. package/src/cli/utils/output-formatter.js +126 -0
  26. package/src/depth-example.ts +66 -0
  27. package/src/gc-pressure-example.ts +158 -0
  28. package/src/global.d.ts +7 -0
  29. package/src/mcp/server.js +469 -0
  30. package/src/performance-example.ts +82 -0
  31. package/src/quality-example.ts +79 -0
  32. package/src/survived-mutations-example.ts +19 -0
  33. package/src/truly-weak-example.ts +37 -0
  34. package/src/weak-test-example.ts +91 -0
@@ -0,0 +1,82 @@
1
+ // Example file to demonstrate CPU cycle and performance tracking
2
+
3
+ export function lightweightFunction(x: number): number {
4
+ return x + 1; // Very fast operation - minimal CPU cycles
5
+ }
6
+
7
+ export function mediumFunction(x: number): number {
8
+ let result = x;
9
+ let i = 0;
10
+ while (i < 100) { // Medium CPU usage
11
+ result = Math.sqrt(result + i);
12
+ i++;
13
+ }
14
+ return result;
15
+ }
16
+
17
+ export function heavyFunction(x: number): number {
18
+ let result = x;
19
+ let i = 0;
20
+ while (i < 1000) { // Heavy CPU usage - many cycles (reduced for testing)
21
+ result = Math.sin(Math.cos(Math.sqrt(result + i)));
22
+ i++;
23
+ }
24
+ return result;
25
+ }
26
+
27
+ export function memoryIntensiveFunction(size: number): number[] {
28
+ const array = new Array(size); // Memory allocation
29
+ let i = 0;
30
+ while (i < size) {
31
+ array[i] = Math.random() * i; // Memory writes
32
+ i++;
33
+ }
34
+ return array;
35
+ }
36
+
37
+ export function recursiveFunction(n: number): number {
38
+ if (n <= 1) {
39
+ return lightweightFunction(n); // Light operation at leaf
40
+ }
41
+ if (n > 5) return n; // Prevent exponential explosion
42
+ return recursiveFunction(n - 1) + recursiveFunction(n - 2); // Limited recursion
43
+ }
44
+
45
+ export function nestedCallsFunction(x: number): number {
46
+ const light = lightweightFunction(x); // Depth 2
47
+ const medium = mediumFunction(light); // Depth 2
48
+ const heavy = heavyFunction(medium); // Depth 2
49
+ return heavy;
50
+ }
51
+
52
+ export function mixedPerformanceFunction(iterations: number): number {
53
+ let result = 0;
54
+ let i = 0;
55
+
56
+ while (i < iterations) {
57
+ if (i % 3 === 0) {
58
+ result += lightweightFunction(i); // Fast path
59
+ } else if (i % 3 === 1) {
60
+ result += mediumFunction(i); // Medium path
61
+ } else {
62
+ result += heavyFunction(i); // Slow path
63
+ }
64
+ i++;
65
+ }
66
+
67
+ return result;
68
+ }
69
+
70
+ // Function that demonstrates different performance characteristics
71
+ export function performanceVariableFunction(mode: 'fast' | 'medium' | 'slow'): number {
72
+ switch (mode) {
73
+ case 'fast':
74
+ return lightweightFunction(42);
75
+ case 'medium':
76
+ return mediumFunction(42);
77
+ case 'slow':
78
+ return heavyFunction(42);
79
+ default:
80
+ return 0;
81
+ }
82
+ }
@@ -0,0 +1,79 @@
1
+ // Example file to demonstrate test quality metrics
2
+
3
+ export function simpleFunction(x: number): number {
4
+ return x * 2;
5
+ }
6
+
7
+ export function complexFunction(data: any): any {
8
+ if (data === null || data === undefined) {
9
+ throw new Error('Data is required');
10
+ }
11
+
12
+ if (typeof data === 'string') {
13
+ return data.toUpperCase();
14
+ } else if (typeof data === 'number') {
15
+ if (data < 0) {
16
+ return Math.abs(data);
17
+ } else if (data === 0) {
18
+ return 1;
19
+ } else {
20
+ return data * data;
21
+ }
22
+ } else if (Array.isArray(data)) {
23
+ return data.map(item => item * 2);
24
+ } else {
25
+ return JSON.stringify(data);
26
+ }
27
+ }
28
+
29
+ export async function asyncFunction(delay: number): Promise<string> {
30
+ return new Promise((resolve, reject) => {
31
+ if (delay < 0) {
32
+ reject(new Error('Delay cannot be negative'));
33
+ } else {
34
+ setTimeout(() => {
35
+ resolve(`Completed after ${delay}ms`);
36
+ }, delay);
37
+ }
38
+ });
39
+ }
40
+
41
+ export function errorProneFunction(input: any): string {
42
+ // This function has potential issues
43
+ return input.toString().toUpperCase();
44
+ }
45
+
46
+ export function wellTestedFunction(a: number, b: number): number {
47
+ if (a === null || a === undefined) {
48
+ throw new Error('Parameter a is required');
49
+ }
50
+ if (b === null || b === undefined) {
51
+ throw new Error('Parameter b is required');
52
+ }
53
+ if (typeof a !== 'number' || typeof b !== 'number') {
54
+ throw new Error('Both parameters must be numbers');
55
+ }
56
+ if (a < 0 || b < 0) {
57
+ throw new Error('Parameters must be non-negative');
58
+ }
59
+
60
+ return a + b;
61
+ }
62
+
63
+ export class Calculator {
64
+ private history: number[] = [];
65
+
66
+ add(a: number, b: number): number {
67
+ const result = a + b;
68
+ this.history.push(result);
69
+ return result;
70
+ }
71
+
72
+ getHistory(): number[] {
73
+ return [...this.history];
74
+ }
75
+
76
+ clearHistory(): void {
77
+ this.history = [];
78
+ }
79
+ }
@@ -0,0 +1,19 @@
1
+ // This file contains functions with absolutely terrible tests that guarantee survived mutations
2
+
3
+ export function demonstrateSurvivedMutations(input: number): number {
4
+ if (input === 42) {
5
+ return 100;
6
+ } else if (input > 50) {
7
+ return input * 2;
8
+ } else {
9
+ return input + 10;
10
+ }
11
+ }
12
+
13
+ export function anotherWeakFunction(x: number, y: number): boolean {
14
+ if (x > y) {
15
+ return true;
16
+ } else {
17
+ return false;
18
+ }
19
+ }
@@ -0,0 +1,37 @@
1
+ // This file contains functions with absolutely terrible tests that guarantee survived mutations
2
+
3
+ export function definitelyWillSurvive(x: number): number {
4
+ if (!(!(x === 5))) {
5
+ return 42;
6
+ } else if (x > 10) {
7
+ return x + 100;
8
+ } else {
9
+ return x * 2;
10
+ }
11
+ }
12
+ export function anotherSurvivor(a: number, b: number): number {
13
+ const sum = a + b;
14
+ if (sum > 50) {
15
+ return sum - 10;
16
+ } else {
17
+ return sum / 2;
18
+ }
19
+ }
20
+ export function booleanSurvivor(x: number): boolean {
21
+ if (x > 0) {
22
+ return true;
23
+ } else {
24
+ return false;
25
+ }
26
+ }
27
+ export function guaranteedSurvivor(input: number): number {
28
+ if (input === 10) {
29
+ const result = 100;
30
+ return result;
31
+ } else if (input === 20) {
32
+ const result = 200;
33
+ return result;
34
+ } else {
35
+ return input + 5;
36
+ }
37
+ }
@@ -0,0 +1,91 @@
1
+ // This file contains functions with weak tests that will allow mutations to survive
2
+
3
+ export function simpleAdd(a: number, b: number): number {
4
+ return a + b;
5
+ }
6
+
7
+ export function complexLogic(x: number, y: number): number {
8
+ if (x > 10) {
9
+ return x * 2;
10
+ } else if (x < 0) {
11
+ return 0;
12
+ } else {
13
+ return x + y;
14
+ }
15
+ }
16
+
17
+ export function boundaryCheck(value: number): string {
18
+ if (value >= 100) {
19
+ return "high";
20
+ } else if (value <= 0) {
21
+ return "low";
22
+ } else {
23
+ return "medium";
24
+ }
25
+ }
26
+
27
+ export function logicalOperations(a: boolean, b: boolean): boolean {
28
+ if (a && b) {
29
+ return true;
30
+ } else if (a || b) {
31
+ return !a;
32
+ } else {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ export function mathOperations(x: number): number {
38
+ const squared = x * x;
39
+ const doubled = x * 2;
40
+ const halved = x / 2;
41
+ return squared + doubled - halved;
42
+ }
43
+
44
+ export function stringOperations(str: string): string {
45
+ if (str.length > 5) {
46
+ return str.toUpperCase();
47
+ } else if (str.length === 0) {
48
+ return "empty";
49
+ } else {
50
+ return str.toLowerCase();
51
+ }
52
+ }
53
+
54
+ export function incrementOperations(x: number): number {
55
+ if (x > 10) {
56
+ return ++x;
57
+ } else if (x > 15) {
58
+ return --x;
59
+ } else {
60
+ return x;
61
+ }
62
+ }
63
+
64
+ export function subtleBugFunction(x: number, y: number): number {
65
+ if (x === 0) {
66
+ return 1;
67
+ } else if (x > 0) {
68
+ return x + y;
69
+ } else {
70
+ return x - y;
71
+ }
72
+ }
73
+
74
+ export function reallyWeakFunction(a: number, b: number): number {
75
+ const result = a * b;
76
+ if (result > 100) {
77
+ return result + 10;
78
+ } else {
79
+ return result - 5;
80
+ }
81
+ }
82
+
83
+ export function guaranteedSurvivedMutations(x: number): number {
84
+ if (x === 5) {
85
+ return 42;
86
+ } else if (x > 10) {
87
+ return x * 2;
88
+ } else {
89
+ return x + 1;
90
+ }
91
+ }