jest-test-lineage-reporter 2.0.2 → 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.
@@ -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
+ }