Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reformat human readable output for test results #377

Closed
wants to merge 10 commits into from
161 changes: 93 additions & 68 deletions src/reporters/humanFormatTransform.ts
peternhale marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export class HumanFormatTransform extends Readable {
constructor(
private readonly testResult: TestResult,
private readonly detailedCoverage: boolean,
private readonly concise: boolean = false,
options?: ReadableOptions
) {
super(options);
this.testResult = testResult;
this.detailedCoverage ??= false;
this.concise = concise;
this.logger = Logger.childFromRoot('HumanFormatTransform');
}

Expand All @@ -45,7 +47,6 @@ export class HumanFormatTransform extends Readable {

@elapsedTime()
public format(): void {
this.formatSummary();
if (!this.testResult.codecoverage || !this.detailedCoverage) {
this.formatTestResults();
}
Expand All @@ -54,8 +55,11 @@ export class HumanFormatTransform extends Readable {
if (this.detailedCoverage) {
this.formatDetailedCov();
}
this.formatCodeCov();
if (!this.concise) {
this.formatCodeCov();
}
}
this.formatSummary();
}

@elapsedTime()
Expand Down Expand Up @@ -110,6 +114,7 @@ export class HumanFormatTransform extends Readable {
: [])
];

this.push(`${EOL}${EOL}`);
tb.createTable(
summaryRowArray,
[
Expand All @@ -135,93 +140,113 @@ export class HumanFormatTransform extends Readable {
runTime: number;
stackTrace: string | null;
}) => {
const msg = elem.stackTrace
? `${elem.message}\n${elem.stackTrace}`
: elem.message;
if (
!this.concise ||
elem.outcome === ApexTestResultOutcome.Fail ||
elem.outcome === ApexTestResultOutcome.CompileFail
) {
const msg = elem.stackTrace
? `${elem.message}\n${elem.stackTrace}`
: elem.message;

testRowArray.push({
name: elem.fullName,
outcome: elem.outcome,
msg: elem.message ? msg : '',
runtime:
elem.outcome !== ApexTestResultOutcome.Fail ? `${elem.runTime}` : ''
});
testRowArray.push({
name: elem.fullName,
outcome: elem.outcome,
msg: elem.message ? msg : '',
runtime:
elem.outcome !== ApexTestResultOutcome.Fail
? `${elem.runTime}`
: ''
});
}
}
);

this.push(`${EOL}${EOL}`);
tb.createTable(
testRowArray,
[
{
key: 'name',
label: nls.localize('testNameColHeader')
},
{ key: 'outcome', label: nls.localize('outcomeColHeader') },
{ key: 'msg', label: nls.localize('msgColHeader') },
{ key: 'runtime', label: nls.localize('runtimeColHeader') }
],
nls.localize('testResultsHeader')
);
if (testRowArray.length > 0) {
this.push(`${EOL}${EOL}`);
tb.createTable(
testRowArray,
[
{
key: 'name',
label: nls.localize('testNameColHeader')
},
{ key: 'outcome', label: nls.localize('outcomeColHeader') },
{ key: 'msg', label: nls.localize('msgColHeader') },
{ key: 'runtime', label: nls.localize('runtimeColHeader') }
],
nls.localize('testResultsHeader')
);
}
}

@elapsedTime()
private formatDetailedCov(): void {
const tb = new TableWriteableStream(this);
const testRowArray: Row[] = [];
this.testResult.tests.forEach((elem: ApexTestResultData) => {
const msg = elem.stackTrace
? `${elem.message}\n${elem.stackTrace}`
: elem.message;
if (
!this.concise ||
elem.outcome === ApexTestResultOutcome.Fail ||
elem.outcome === ApexTestResultOutcome.CompileFail
) {
const msg = elem.stackTrace
? `${elem.message}\n${elem.stackTrace}`
: elem.message;

if (elem.perClassCoverage) {
elem.perClassCoverage.forEach((perClassCov) => {
if (elem.perClassCoverage) {
elem.perClassCoverage.forEach((perClassCov) => {
testRowArray.push({
name: elem.fullName,
coveredClassName: perClassCov.apexClassOrTriggerName,
outcome: elem.outcome,
coveredClassPercentage: perClassCov.percentage,
msg: elem.message ? msg : '',
runtime: `${elem.runTime}`
});
});
} else {
testRowArray.push({
name: elem.fullName,
coveredClassName: perClassCov.apexClassOrTriggerName,
coveredClassName: '',
outcome: elem.outcome,
coveredClassPercentage: perClassCov.percentage,
coveredClassPercentage: '',
peternhale marked this conversation as resolved.
Show resolved Hide resolved
msg: elem.message ? msg : '',
runtime: `${elem.runTime}`
});
});
} else {
testRowArray.push({
name: elem.fullName,
coveredClassName: '',
outcome: elem.outcome,
coveredClassPercentage: '',
msg: elem.message ? msg : '',
runtime: `${elem.runTime}`
});
}
}
});

this.push(os.EOL.repeat(2));
tb.createTable(
testRowArray,
[
{
key: 'name',
label: nls.localize('testNameColHeader')
},
{
key: 'coveredClassName',
label: nls.localize('classTestedHeader')
},
{
key: 'outcome',
label: nls.localize('outcomeColHeader')
},
{
key: 'coveredClassPercentage',
label: nls.localize('percentColHeader')
},
{ key: 'msg', label: nls.localize('msgColHeader') },
{ key: 'runtime', label: nls.localize('runtimeColHeader') }
],
nls.localize('detailedCodeCovHeader', [this.testResult.summary.testRunId])
);
if (testRowArray.length > 0) {
this.push(os.EOL.repeat(2));
tb.createTable(
testRowArray,
[
{
key: 'name',
label: nls.localize('testNameColHeader')
},
{
key: 'coveredClassName',
label: nls.localize('classTestedHeader')
},
{
key: 'outcome',
label: nls.localize('outcomeColHeader')
},
{
key: 'coveredClassPercentage',
label: nls.localize('percentColHeader')
},
{ key: 'msg', label: nls.localize('msgColHeader') },
{ key: 'runtime', label: nls.localize('runtimeColHeader') }
],
nls.localize('detailedCodeCovHeader', [
this.testResult.summary.testRunId
])
);
}
}

@elapsedTime('elapsedTime', LoggerLevel.TRACE)
Expand Down
Loading