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

fix: respect UT flags when running with json #650

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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