Skip to content

Commit

Permalink
fix: respect UT flags when running with json (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele authored Jun 6, 2023
1 parent 8c3e3e7 commit 12b002c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export class DeployResultFormatter implements Formatter<DeployResultJson> {
}

public getJson(): DeployResultJson {
// only generate reports if test results are presented
if (this.result.response?.numberTestsTotal) {
if (this.coverageOptions.reportFormats?.length) {
this.createCoverageReport('no-map');
}
if (this.junit) {
this.createJunitResults();
}
}
if (this.verbosity === 'concise') {
return {
...this.result.response,
Expand All @@ -81,7 +90,7 @@ export class DeployResultFormatter implements Formatter<DeployResultJson> {
return {
...this.result.response,
files: this.absoluteFiles,
...(this.result.replacements.size
...(this.result.replacements?.size
? {
replacements: Object.fromEntries(this.result.replacements),
}
Expand Down
1 change: 1 addition & 0 deletions test/utils/deployResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const getDeployResponse = (
},
];
response.details.runTestResult.numFailures = '0';
response.numberTestsTotal = 1;
}
response.runTestsEnabled = true;
response.numberTestErrors = 0;
Expand Down
19 changes: 19 additions & 0 deletions test/utils/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ describe('deployResultFormatter', () => {
});
});

it('will write test output when in json mode', async () => {
const deployResult = getDeployResult('passedTest');
const formatter = new DeployResultFormatter(deployResult, {
junit: true,
'coverage-formatters': ['text', 'cobertura'],
});
// private method stub
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const coverageReportStub = sandbox.stub(formatter, 'createCoverageReport');
// private method stub
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const junitStub = sandbox.stub(formatter, 'createJunitResults');
formatter.getJson();
expect(coverageReportStub.calledOnce).to.equal(true);
expect(junitStub.calledOnce).to.equal(true);
});

it('teamcity', () => {
const result = getCoverageFormattersOptions(['teamcity']);
expect(result).to.deep.equal({
Expand Down

0 comments on commit 12b002c

Please sign in to comment.