Skip to content

Commit 1172fea

Browse files
committed
chore(detector): adds average of test smells
1 parent ee96243 commit 1172fea

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

detector/src/reporters/Html.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import { AgreggatorSmellls, ExportOptions, SmellsList } from './types';
33

44
export class SmellsAggreagtor implements AgreggatorSmellls {
55
constructor(
6-
private smellLists: SmellsList[],
6+
private totalTestFiles: SmellsList[],
77
private exportOptions: ExportOptions
88
) { }
99

1010
async build(): Promise<void> {
1111
try {
12-
const totalSmells = this.smellLists.reduce((previous, current) => previous + current.smells.length, 0);
12+
const totalFiles = this.totalTestFiles.length;
13+
const totalSmells = this.totalTestFiles.reduce((previous, current) => previous + current.smells.length, 0);
1314

1415
const output = new HtmlOutput();
1516
await output.writeTo({
16-
data: this.smellLists,
1717
totalSmells,
18-
averageSmellsPerTestFile: 5
18+
data: this.totalTestFiles,
19+
averageSmellsPerTestFile: totalSmells / totalFiles
1920
}, this.exportOptions);
2021
} catch (err) {
2122
console.log(err);

detector/test/smells-aggregator.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('smells aggregator', () => {
8080
expect(write.mock.calls[0][0].totalSmells).toEqual(1);
8181
});
8282

83-
test('two test file with 10 smells detected has average of 5 smells per test file', async () => {
83+
test('two test file with 5 smells each, should have average of 5 smells per test file', async () => {
8484
const smell: Smell = SmellsBuilder.console(0, 1, 10, 20);
8585
const smellsFound: SmellsList[] = [
8686
{
@@ -104,4 +104,29 @@ describe('smells aggregator', () => {
104104

105105
expect(write.mock.calls[0][0].averageSmellsPerTestFile).toEqual(5);
106106
});
107+
108+
test('two test file with 4 smells in one of them, should have average of 2 smells per test file', async () => {
109+
const smell: Smell = SmellsBuilder.console(0, 1, 10, 20);
110+
const smellsFound: SmellsList[] = [
111+
{
112+
smells: [smell, smell, smell, smell],
113+
language: SupportedLanguages.javascript,
114+
fileName: 'first_test.js'
115+
},
116+
{
117+
smells: [],
118+
language: SupportedLanguages.javascript,
119+
fileName: 'second_test.js'
120+
},
121+
];
122+
const exportsOptions: ExportOptions = { to: '.' };
123+
124+
const write = vi.mocked(HtmlOutput.prototype.writeTo = vi.fn());
125+
126+
const reporter = new SmellsAggreagtor(smellsFound, exportsOptions);
127+
128+
await reporter.build();
129+
130+
expect(write.mock.calls[0][0].averageSmellsPerTestFile).toEqual(2);
131+
});
107132
});

0 commit comments

Comments
 (0)