Skip to content

Commit

Permalink
chore(detector): show number of test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
marabesi committed Dec 8, 2024
1 parent 2e6963f commit cb45924
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion detector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"ts-node": "^10.9.2"
},
"scripts": {
"compile": "rm -rf build/ types && tsc && cp -R ./src/reporters/layout ./build/src/reporters/",
"compile": "rm -rf build/ types/ && tsc && cp -R ./src/reporters/ ./build/src/reporters/",
"watch": "webpack --watch",
"clean": "rm -rf out/ dist/ types/",
"compile-tests": "npm run clean && tsc -p . --outDir out",
Expand Down
1 change: 1 addition & 0 deletions detector/src/reporters/SmellsAgreggator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SmellsAggreagtor implements AgreggatorSmellls {
totalSmells,
data: this.totalTestFiles,
averageSmellsPerTestFile: totalSmells / totalFiles,
totalTestCases: 0,
}, this.exportOptions);
} catch (err) {
console.log(err);
Expand Down
6 changes: 6 additions & 0 deletions detector/src/reporters/layout/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ <h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"
<div
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">

<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white" data-testid="total-test-cases">{{ totalTestCases }}</h5>
<p class="font-normal text-gray-700 dark:text-gray-400" data-testid="title-test-cases">Test cases</p>
</div>
<div
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">

<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white" data-testid="total-test-files">{{ data.length }}</h5>
<p class="font-normal text-gray-700 dark:text-gray-400" data-testid="title-test-files">Test files</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions detector/src/reporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AggregatedData {
data: SmellsList[],
totalSmells: number,
averageSmellsPerTestFile: number,
totalTestCases: number,
}

export interface ExportOptions {
Expand Down
7 changes: 6 additions & 1 deletion detector/test/html-report-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { readFileSync } from 'fs';

export async function buildEmptyHtmlReportForTestSmells(exportsOptions: ExportOptions, filePath: string) {
const smellsFound: SmellsList[] = [];
const aggregatedData: AggregatedData = { data: smellsFound, totalSmells: 0, averageSmellsPerTestFile: 0 };
const aggregatedData: AggregatedData = {
data: smellsFound,
totalSmells: 0,
averageSmellsPerTestFile: 0,
totalTestCases: 0,
};

const reporter = new HtmlOutput();
await reporter.writeTo(aggregatedData, exportsOptions);
Expand Down
8 changes: 8 additions & 0 deletions detector/test/html-report.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('html report', () => {
expect(root.querySelector('[data-testid="total-test-files"]')?.textContent).toEqual('0');
expect(root.querySelector('[data-testid="title-test-files"]')?.textContent).toEqual('Test files');
});

test('renders the number of test cases', async () => {
const generatedHtml = await buildEmptyHtmlReportForTestSmells(exportsOptions, filePath);
const root = parse(generatedHtml);

expect(root.querySelector('[data-testid="total-test-cases"]')?.textContent).toEqual('0');
expect(root.querySelector('[data-testid="title-test-cases"]')?.textContent).toEqual('Test cases');
});
});

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

0 comments on commit cb45924

Please sign in to comment.