Skip to content

Commit

Permalink
feat(report): add Mutation Coverage based on Covered code column (#3310)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivganes authored Aug 6, 2024
1 parent 218d572 commit d68d9c8
Show file tree
Hide file tree
Showing 52 changed files with 66 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Column<TMetric> {
width?: TableWidth;
category: ColumnCategory;
isBold?: true;
group?: string;
}

@customElement('mte-metrics-table')
Expand Down Expand Up @@ -67,9 +68,11 @@ export class MutationTestReportTestMetricsTable<TFile, TMetric> extends RealTime
}

private renderTableHeadRow() {
const nonMutationScoreColumns = this.columns.filter((column) => column.group !== 'Mutation score');
const mutationScoreColumns = this.columns.filter((column) => column.group === 'Mutation score');
return html`<thead class="border-b border-gray-200 text-center text-sm">
<tr>
<th scope="col" class="px-4 py-4">
<th rowspan="2" scope="col" class="px-4 py-4">
<div class="flex items-center justify-around">
<span>File / Directory</span
><a
Expand All @@ -81,8 +84,16 @@ export class MutationTestReportTestMetricsTable<TFile, TMetric> extends RealTime
>
</div>
</th>
${mutationScoreColumns.length>0 ? html`<th colspan="4" class="px-2 even:bg-gray-100">Mutation Score</th>`:``}
${repeat(
this.columns,
nonMutationScoreColumns,
(column) => column.key,
(column) => this.renderTableHead(column),
)}
</tr>
<tr>
${repeat(
mutationScoreColumns,
(column) => column.key,
(column) => this.renderTableHead(column),
)}
Expand All @@ -95,10 +106,10 @@ export class MutationTestReportTestMetricsTable<TFile, TMetric> extends RealTime
const header = column.tooltip
? html`<mte-tooltip title="${column.tooltip}" id="${id}">${column.label}</mte-tooltip>`
: html`<span id="${id}">${column.label}</span>`;
if (column.category === 'percentage') {
return html` <th colspan="2" class="px-2 even:bg-gray-100"> ${header} </th>`;
if (column.group) {
return html` <th colspan="2" class="px-2 bg-gray-200"> ${header} </th>`;
}
return html`<th class="w-24 px-2 even:bg-gray-100 2xl:w-28">
return html`<th rowspan="2" class="w-24 px-2 even:bg-gray-100 2xl:w-28">
<div class="inline-block">${header}</div>
</th>`;
}
Expand Down
12 changes: 10 additions & 2 deletions packages/elements/src/components/mutant-view/mutant-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ export class MutationTestReportMutantViewComponent extends RealTimeElement {
const COLUMNS: Column<Metrics>[] = [
{
key: 'mutationScore',
label: 'Mutation score',
label: 'Of total',
tooltip: 'The percentage of mutants that were detected. The higher, the better!',
category: 'percentage',
group: 'Mutation score'
},
{
key: 'mutationScoreBasedOnCoveredCode',
label: 'Of covered',
tooltip: 'Mutation score based on only the code covered by tests',
category: 'percentage',
group: 'Mutation score'
},
{
key: 'killed',
Expand Down Expand Up @@ -98,7 +106,7 @@ const COLUMNS: Column<Metrics>[] = [
label: 'Ignored',
tooltip: "These mutants weren't tested because they are ignored. Either by user action, or for another reason.",
category: 'number',
},
},
{
key: 'runtimeErrors',
label: 'Runtime errors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ test.describe('Directory report page', () => {
await Promise.all([
row.progressBar().expectPercentage('8.70'),
expect(row.mutationScore()).toHaveText('8.70'),
row.testStrengthProgressBar().expectPercentage('66.67'),
expect(row.mutationScoreBasedOnCoveredCode()).toHaveText('66.67'),
expect(row.killed()).toHaveText('2'),
expect(row.survived()).toHaveText('1'),
expect(row.timeout()).toHaveText('0'),
expect(row.noCoverage()).toHaveText('20'),
expect(row.ignored()).toHaveText('0'),
expect(row.ignored()).toHaveText('0'),
expect(row.runtimeErrors()).toHaveText('0'),
expect(row.compileErrors()).toHaveText('3'),
expect(row.totalDetected()).toHaveText('2'),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions packages/elements/test/integration/po/ResultTableRow.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export class ResultTableRow extends PageObject {
public name = () => this.nameTableElement().innerText();
public progressBar = () => new ProgressBar(this.$('td:nth-child(2)>div.rounded-full'), this.browser);
public mutationScore = () => this.$('td:nth-child(3)');
public killed = () => this.$('td:nth-child(4)');
public survived = () => this.$('td:nth-child(5)');
public timeout = () => this.$('td:nth-child(6)');
public noCoverage = () => this.$('td:nth-child(7)');
public ignored = () => this.$('td:nth-child(8)');
public runtimeErrors = () => this.$('td:nth-child(9)');
public compileErrors = () => this.$('td:nth-child(10)');
public totalDetected = () => this.$('td:nth-child(11)');
public totalUndetected = () => this.$('td:nth-child(12)');
public totalMutants = () => this.$('td:nth-child(13)');
public testStrengthProgressBar = () => new ProgressBar(this.$('td:nth-child(4)>div.rounded-full'), this.browser);
public mutationScoreBasedOnCoveredCode = () => this.$('td:nth-child(5)');
public killed = () => this.$('td:nth-child(6)');
public survived = () => this.$('td:nth-child(7)');
public timeout = () => this.$('td:nth-child(8)');
public noCoverage = () => this.$('td:nth-child(9)');
public ignored = () => this.$('td:nth-child(10)');
public runtimeErrors = () => this.$('td:nth-child(11)');
public compileErrors = () => this.$('td:nth-child(12)');
public totalDetected = () => this.$('td:nth-child(13)');
public totalUndetected = () => this.$('td:nth-child(14)');
public totalMutants = () => this.$('td:nth-child(15)');
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ describe(MutationTestReportMutantViewComponent.name, () => {
const expectedColumns: Column<Metrics>[] = [
{
key: 'mutationScore',
label: 'Mutation score',
label: 'Of total',
tooltip: 'The percentage of mutants that were detected. The higher, the better!',
category: 'percentage',
group: 'Mutation score'
},
{
key: 'mutationScoreBasedOnCoveredCode',
label: 'Of covered',
tooltip: 'Mutation score based on only the code covered by tests',
category: 'percentage',
group: 'Mutation score'
},
{
key: 'killed',
Expand Down
19 changes: 16 additions & 3 deletions packages/elements/test/unit/components/totals.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ describe(MutationTestReportTestMetricsTable.name, () => {
beforeEach(async () => {
sut = new CustomElementFixture('mte-metrics-table');
sut.element.columns = [
{ key: 'mutationScore', label: 'Mutation score', category: 'percentage' },
{
key: 'mutationScore',
label: 'Total',
tooltip: 'The percentage of mutants that were detected. The higher, the better!',
category: 'percentage',
group: 'Mutation score'
},
{
key: 'mutationScoreBasedOnCoveredCode',
label: 'Of covered',
tooltip: 'Mutation score based on only the code covered by tests',
category: 'percentage',
group: 'Mutation score'
},
{ key: 'killed', label: '# Killed', category: 'number' },
{ key: 'survived', label: '# Survived', category: 'number' },
{ key: 'timeout', label: '# Timeout', category: 'number' },
Expand Down Expand Up @@ -40,8 +53,8 @@ describe(MutationTestReportTestMetricsTable.name, () => {
await sut.whenStable();
const table = sut.$('table');
expect(table).ok;
expect(table.querySelectorAll('thead th')).lengthOf(12);
expect(table.querySelectorAll('tbody th, tbody td')).lengthOf(13);
expect(table.querySelectorAll('thead th')).lengthOf(14);
expect(table.querySelectorAll('tbody th, tbody td')).lengthOf(15);
});

it('should show a table with a 3 rows for a directory result with 2 directories and one file', async () => {
Expand Down

0 comments on commit d68d9c8

Please sign in to comment.