Skip to content

Commit cb45924

Browse files
committed
chore(detector): show number of test cases
1 parent 2e6963f commit cb45924

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

detector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"ts-node": "^10.9.2"
3737
},
3838
"scripts": {
39-
"compile": "rm -rf build/ types && tsc && cp -R ./src/reporters/layout ./build/src/reporters/",
39+
"compile": "rm -rf build/ types/ && tsc && cp -R ./src/reporters/ ./build/src/reporters/",
4040
"watch": "webpack --watch",
4141
"clean": "rm -rf out/ dist/ types/",
4242
"compile-tests": "npm run clean && tsc -p . --outDir out",

detector/src/reporters/SmellsAgreggator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class SmellsAggreagtor implements AgreggatorSmellls {
1717
totalSmells,
1818
data: this.totalTestFiles,
1919
averageSmellsPerTestFile: totalSmells / totalFiles,
20+
totalTestCases: 0,
2021
}, this.exportOptions);
2122
} catch (err) {
2223
console.log(err);

detector/src/reporters/layout/example.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ <h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"
5454
<div
5555
class="mb-5 max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700">
5656

57+
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white" data-testid="total-test-cases">{{ totalTestCases }}</h5>
58+
<p class="font-normal text-gray-700 dark:text-gray-400" data-testid="title-test-cases">Test cases</p>
59+
</div>
60+
<div
61+
class="mb-5 max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700">
62+
5763
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white" data-testid="total-test-files">{{ data.length }}</h5>
5864
<p class="font-normal text-gray-700 dark:text-gray-400" data-testid="title-test-files">Test files</p>
5965
</div>

detector/src/reporters/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface AggregatedData {
1515
data: SmellsList[],
1616
totalSmells: number,
1717
averageSmellsPerTestFile: number,
18+
totalTestCases: number,
1819
}
1920

2021
export interface ExportOptions {

detector/test/html-report-builder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { readFileSync } from 'fs';
44

55
export async function buildEmptyHtmlReportForTestSmells(exportsOptions: ExportOptions, filePath: string) {
66
const smellsFound: SmellsList[] = [];
7-
const aggregatedData: AggregatedData = { data: smellsFound, totalSmells: 0, averageSmellsPerTestFile: 0 };
7+
const aggregatedData: AggregatedData = {
8+
data: smellsFound,
9+
totalSmells: 0,
10+
averageSmellsPerTestFile: 0,
11+
totalTestCases: 0,
12+
};
813

914
const reporter = new HtmlOutput();
1015
await reporter.writeTo(aggregatedData, exportsOptions);

detector/test/html-report.integration.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ describe('html report', () => {
4949
expect(root.querySelector('[data-testid="total-test-files"]')?.textContent).toEqual('0');
5050
expect(root.querySelector('[data-testid="title-test-files"]')?.textContent).toEqual('Test files');
5151
});
52+
53+
test('renders the number of test cases', async () => {
54+
const generatedHtml = await buildEmptyHtmlReportForTestSmells(exportsOptions, filePath);
55+
const root = parse(generatedHtml);
56+
57+
expect(root.querySelector('[data-testid="total-test-cases"]')?.textContent).toEqual('0');
58+
expect(root.querySelector('[data-testid="title-test-cases"]')?.textContent).toEqual('Test cases');
59+
});
5260
});
5361

5462
describe('when there are test smells', () => {

0 commit comments

Comments
 (0)