Skip to content

Commit 0ba4e7a

Browse files
committed
fix(SummaryReport): Ignored tests are not taken in consideration to calculate percentages
1 parent 1e533c9 commit 0ba4e7a

10 files changed

+1948
-1860
lines changed

output/examples.json

+917-917
Large diffs are not rendered by default.

output/examples.yml

+917-917
Large diffs are not rendered by default.

src/models/outputs/test-model.test.ts

+73-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TestModel, testModelIsPassing} from './test-model';
1+
import {TestModel, testModelIsFailing, testModelIsNotFailing, testModelIsPassing} from './test-model';
22

33
describe('TestModel', () => {
44
it('Valid is passing', () => {
@@ -10,17 +10,27 @@ describe('TestModel', () => {
1010
expect(testModelIsPassing(test)).toBeTruthy();
1111
});
1212

13-
it('Ignored is passing', () => {
13+
it('Ignored is not passing', () => {
1414
const test: TestModel = {
1515
description: '',
1616
name: '',
1717
valid: false,
1818
ignored: true
1919
};
20-
expect(testModelIsPassing(test)).toBeTruthy();
20+
expect(testModelIsPassing(test)).toBeFalsy();
2121
});
2222

23-
it('Not valid and not ignored is not passingis passing', () => {
23+
it('Valid and ignored is not passing', () => {
24+
const test: TestModel = {
25+
description: '',
26+
name: '',
27+
valid: true,
28+
ignored: true
29+
};
30+
expect(testModelIsPassing(test)).toBeFalsy();
31+
});
32+
33+
it('Not valid and not ignored and not valid is not passing', () => {
2434
const test: TestModel = {
2535
description: '',
2636
name: '',
@@ -29,4 +39,63 @@ describe('TestModel', () => {
2939
};
3040
expect(testModelIsPassing(test)).toBeFalsy();
3141
});
42+
43+
44+
45+
it('Valid is not failing', () => {
46+
const test: TestModel = {
47+
description: '',
48+
name: '',
49+
valid: true
50+
};
51+
expect(testModelIsNotFailing(test)).toBeTruthy();
52+
});
53+
54+
it('Ignored is not failing', () => {
55+
const test: TestModel = {
56+
description: '',
57+
name: '',
58+
valid: false,
59+
ignored: true
60+
};
61+
expect(testModelIsNotFailing(test)).toBeTruthy();
62+
});
63+
64+
it('Valid and ignored is not passing', () => {
65+
const test: TestModel = {
66+
description: '',
67+
name: '',
68+
valid: false,
69+
};
70+
expect(testModelIsNotFailing(test)).toBeFalsy();
71+
});
72+
73+
it('Not valid and not ignored is not passing is not failing', () => {
74+
const test: TestModel = {
75+
description: '',
76+
name: '',
77+
valid: false,
78+
ignored: false
79+
};
80+
expect(testModelIsNotFailing(test)).toBeFalsy();
81+
});
82+
83+
it('Not valid and ignored is non failing', () => {
84+
const test: TestModel = {
85+
description: '',
86+
name: '',
87+
valid: false,
88+
ignored: true
89+
};
90+
expect(testModelIsFailing(test)).toBeFalsy();
91+
});
92+
93+
it('Not valid and not ignored is non failing', () => {
94+
const test: TestModel = {
95+
description: '',
96+
name: '',
97+
valid: false,
98+
};
99+
expect(testModelIsFailing(test)).toBeTruthy();
100+
});
32101
});

src/models/outputs/test-model.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,22 @@ export interface TestModel {
66
}
77

88
export function testModelIsPassing(test: { valid: boolean, ignored?: boolean }): boolean {
9-
return test.ignored || test.valid;
9+
if (test.ignored === true) {
10+
return false;
11+
}
12+
return test.valid === true;
13+
}
14+
15+
export function testModelIsFailing(test: { valid: boolean, ignored?: boolean }): boolean {
16+
if (test.ignored === true) {
17+
return false;
18+
}
19+
return test.valid === false;
20+
}
21+
22+
export function testModelIsNotFailing(test: { valid: boolean, ignored?: boolean }): boolean {
23+
if (test.ignored === true) {
24+
return true;
25+
}
26+
return test.valid !== false;
1027
}

src/outputs/summary-test-output.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {TestsAnalyzer} from './tests-analyzer';
2-
import {TestModel, testModelIsPassing} from '../models/outputs/test-model';
2+
import {TestModel, testModelIsFailing, testModelIsNotFailing, testModelIsPassing} from '../models/outputs/test-model';
33
import {RequisitionModel} from '../models/outputs/requisition-model';
44
import {PublisherModel} from '../models/outputs/publisher-model';
55
import {SubscriptionModel} from '../models/outputs/subscription-model';
@@ -140,7 +140,7 @@ export class SummaryTestOutput {
140140
}
141141

142142
private printFailingTests(report: ReportModel, hierarchy: string[]) {
143-
const failing = !testModelIsPassing(report);
143+
const failing = testModelIsFailing(report);
144144
if (failing || this.options.showPassingTests) {
145145
Object.keys(report.hooks || {})
146146
.forEach((key: string) => this.printHookTests(report.hooks![key], key, hierarchy));

src/outputs/tests-analyzer.test.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,20 @@ describe('TestsAnalyzer', () => {
8080

8181
const test: ReportModel = {
8282
name: 'name',
83-
valid: true,
83+
valid: false,
8484
hooks: {
85-
onInit: {valid: true, tests: [createTest(false, true), createTest(true, true)]}
85+
onInit: {valid: true, tests: [createTest(false, true), createTest(true, true)]},
86+
onFinish: {valid: false, tests: [createTest(true, false), createTest(false, undefined)]}
8687
},
8788
};
8889

8990
const testsAnalyzer = new TestsAnalyzer().addTest(test);
9091

91-
expect(testsAnalyzer.getFailingTests().length).toBe(0);
92-
expect(testsAnalyzer.getTests().length).toBe(2);
93-
expect(testsAnalyzer.getPercentage()).toBe(100);
92+
expect(testsAnalyzer.getFailingTests().length).toBe(1);
93+
expect(testsAnalyzer.getTests().length).toBe(4);
94+
expect(testsAnalyzer.getPassingTests().length).toBe(1);
95+
expect(testsAnalyzer.getNotIgnoredTests().length).toBe(2);
96+
expect(testsAnalyzer.getPercentage()).toBe(50);
9497
});
9598

9699
it('Should ignore ignored test to validate', () => {
@@ -128,7 +131,7 @@ describe('TestsAnalyzer', () => {
128131
const testsAnalyzer = new TestsAnalyzer().addTest(test);
129132

130133
expect(testsAnalyzer.getFailingTests().length).toBe(1);
131-
expect(testsAnalyzer.getPassingTests().length).toBe(4);
134+
expect(testsAnalyzer.getPassingTests().length).toBe(3);
132135
expect(testsAnalyzer.getIgnoredList().length).toBe(1);
133136
expect(testsAnalyzer.getTests().length).toBe(5);
134137
expect(testsAnalyzer.getNotIgnoredTests().length).toBe(4);
@@ -149,7 +152,7 @@ describe('TestsAnalyzer', () => {
149152
const testsAnalyzer = new TestsAnalyzer().addTest(test);
150153

151154
expect(testsAnalyzer.getFailingTests().length).toBe(0);
152-
expect(testsAnalyzer.getPassingTests().length).toBe(1);
155+
expect(testsAnalyzer.getPassingTests().length).toBe(0);
153156
expect(testsAnalyzer.getIgnoredList().length).toBe(1);
154157
expect(testsAnalyzer.getTests().length).toBe(1);
155158
expect(testsAnalyzer.getNotIgnoredTests().length).toBe(0);

src/outputs/tests-analyzer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ export class TestsAnalyzer {
2424
}
2525

2626
public getIgnoredList(): TestModel[] {
27-
return this.tests.filter(test => test.ignored !== false && test.ignored !== undefined);
27+
return this.tests.filter(test => test.ignored === true && test.ignored !== undefined);
2828
}
2929

3030
public getPassingTests(): TestModel[] {
31-
return this.tests.filter(test => testModelIsPassing(test));
31+
return this.tests.filter(test => test.valid === true && (test.ignored === false || test.ignored === undefined));
3232
}
3333

3434
public getFailingTests(): TestModel[] {
35-
return this.tests.filter(test => !testModelIsPassing(test));
35+
return this.tests.filter(test => test.valid === false && (test.ignored === false || test.ignored === undefined));
3636
}
3737

3838
public getPercentage(): number {
39-
let percentage = Math.trunc(10000 * this.getPassingTests().length / this.getTests().length) / 100;
40-
if (isNaN(percentage)) {
41-
percentage = 100;
39+
const notIgnoredTestsLength = this.getNotIgnoredTests().length;
40+
if (notIgnoredTestsLength === 0) {
41+
return 100;
4242
}
43-
return percentage;
43+
return Math.trunc(10000 * this.getPassingTests().length / notIgnoredTestsLength) / 100;
4444
}
4545

4646
private findRequisitions(requisition: ReportModel) {

src/reporters/hook-reporter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {HookModel} from '../models/outputs/hook-model';
2-
import {testModelIsPassing} from '../models/outputs/test-model';
2+
import {testModelIsNotFailing} from '../models/outputs/test-model';
33

44
export class HookReporter {
55
private readonly hook: HookModel;
@@ -16,7 +16,7 @@ export class HookReporter {
1616
public addValues(hookModel: HookModel = {valid: true, tests: [], arguments: {}}): HookModel {
1717
this.hook.tests = this.hook.tests.concat(hookModel.tests);
1818
this.hook.arguments = Object.assign({}, this.hook.arguments, hookModel.arguments);
19-
this.hook.valid = this.hook.tests.every(test => testModelIsPassing(test));
19+
this.hook.valid = this.hook.tests.every(test => testModelIsNotFailing(test));
2020
return this.hook;
2121
}
2222
}

src/requisition-runners/requisition-runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ComponentParentBackupper} from '../components/component-parent-backupper
1111
import {ComponentImporter} from './component-importer';
1212
import {RequisitionAdopter} from '../components/requisition-adopter';
1313
import {NotificationEmitter, Notifications} from '../notifications/notification-emitter';
14-
import {testModelIsPassing} from '../models/outputs/test-model';
14+
import {testModelIsNotFailing} from '../models/outputs/test-model';
1515

1616
export class RequisitionRunner {
1717

@@ -127,7 +127,7 @@ export class RequisitionRunner {
127127
const report = await this.requisitionReporter!.execute();
128128
report.requisitions = childrenReport;
129129
report.valid = report.valid &&
130-
report.requisitions.every((requisition) => testModelIsPassing(requisition)) &&
130+
report.requisitions.every((requisition) => testModelIsNotFailing(requisition)) &&
131131
Object.keys(report.hooks || {}).every((key: string) => report.hooks ? report.hooks[key].valid : true);
132132
Logger.debug(`Requisition ${this.requisition.name} went through the happy path`);
133133
return report;

tslint.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"no-duplicate-variable": true,
1212
"no-var-keyword": true,
1313
"no-unused-expression": true,
14-
"no-use-before-declare": true,
1514
"no-var-requires": false,
1615
"no-require-imports": false,
1716
"one-line": [true, "check-else", "check-whitespace", "check-open-brace"],

0 commit comments

Comments
 (0)