Skip to content

Commit

Permalink
fix: find server errors and display them with FileResponse errors (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele authored Sep 22, 2021
1 parent 4c443c8 commit 99df1ca
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
32 changes: 28 additions & 4 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FileResponse,
MetadataApiDeployStatus,
RequestStatus,
DeployMessage,
} from '@salesforce/source-deploy-retrieve';
import { ResultFormatter, ResultFormatterOptions, toArray } from './resultFormatter';

Expand Down Expand Up @@ -126,10 +127,33 @@ export class DeployResultFormatter extends ResultFormatter {
}

protected displayFailures(): void {
if (this.hasStatus(RequestStatus.Failed) && this.fileResponses?.length) {
const failures = this.fileResponses.filter((f) => f.state === 'Failed');
this.sortFileResponses(failures);
this.asRelativePaths(failures);
if (this.hasStatus(RequestStatus.Failed)) {
const failures: Array<FileResponse | DeployMessage> = [];
const fileResponseFailures: Map<string, string> = new Map<string, string>();

if (this.fileResponses?.length) {
const fileResponses: FileResponse[] = [];
this.fileResponses
.filter((f) => f.state === 'Failed')
.map((f: FileResponse & { error: string }) => {
fileResponses.push(f);
fileResponseFailures.set(`${f.type}#${f.fullName}`, f.error);
});
this.sortFileResponses(fileResponses);
this.asRelativePaths(fileResponses);
failures.push(...fileResponses);
}

const deployMessages = toArray(this.result?.response?.details?.componentFailures);
if (deployMessages.length > failures.length) {
// if there's additional failures in the API response, find the failure and add it to the output
deployMessages.map((deployMessage) => {
if (!fileResponseFailures.has(`${deployMessage.componentType}#${deployMessage.fullName}`)) {
// duplicate the problem message to the error property for displaying in the table
failures.push(Object.assign(deployMessage, { error: deployMessage.problem }));
}
});
}

this.ux.log('');
this.ux.styledHeader(chalk.red(`Component Failures [${failures.length}]`));
Expand Down
39 changes: 21 additions & 18 deletions test/formatters/deployResultFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ describe('DeployResultFormatter', () => {
expect(tableStub.firstCall.args[0]).to.deep.equal(fileResponses);
});

it('should output as expected for a failure', async () => {
it('should output as expected for a failure and exclude duplicate information', async () => {
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultFailure);
formatter.display();
expect(styledHeaderStub.calledOnce).to.equal(true);
expect(logStub.calledTwice).to.equal(true);
expect(tableStub.called).to.equal(true);
expect(styledHeaderStub.firstCall.args[0]).to.contain('Component Failures [1]');
expect(styledHeaderStub.args[0][0]).to.include('Component Failures [1]');
const fileResponses = deployResultFailure.getFileResponses();
resolveExpectedPaths(fileResponses);
expect(tableStub.firstCall.args[0]).to.deep.equal(fileResponses);
Expand All @@ -105,32 +105,35 @@ describe('DeployResultFormatter', () => {
it('should output as expected for a test failure with verbose', async () => {
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestFailure);
formatter.display();
expect(styledHeaderStub.calledTwice).to.equal(true);
expect(logStub.callCount).to.equal(5);
expect(tableStub.calledTwice).to.equal(true);
expect(styledHeaderStub.firstCall.args[0]).to.contain('Test Failures [1]');
expect(styledHeaderStub.secondCall.args[0]).to.contain('Apex Code Coverage');
expect(styledHeaderStub.calledThrice).to.equal(true);
expect(logStub.callCount).to.equal(7);
expect(tableStub.calledThrice).to.equal(true);
expect(styledHeaderStub.args[0][0]).to.include('Component Failures [1]');
expect(styledHeaderStub.args[1][0]).to.include('Test Failures [1]');
expect(styledHeaderStub.args[2][0]).to.include('Apex Code Coverage');
});

it('should output as expected for passing tests with verbose', async () => {
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestSuccess);
formatter.display();
expect(styledHeaderStub.calledTwice).to.equal(true);
expect(logStub.callCount).to.equal(5);
expect(tableStub.calledTwice).to.equal(true);
expect(styledHeaderStub.firstCall.args[0]).to.contain('Test Success [1]');
expect(styledHeaderStub.secondCall.args[0]).to.contain('Apex Code Coverage');
expect(styledHeaderStub.calledThrice).to.equal(true);
expect(logStub.callCount).to.equal(7);
expect(tableStub.calledThrice).to.equal(true);
expect(styledHeaderStub.args[0][0]).to.include('Component Failures [1]');
expect(styledHeaderStub.args[1][0]).to.include('Test Success [1]');
expect(styledHeaderStub.args[2][0]).to.include('Apex Code Coverage');
});

it('should output as expected for passing and failing tests with verbose', async () => {
const formatter = new DeployResultFormatter(logger, ux, { verbose: true }, deployResultTestSuccessAndFailure);
formatter.display();
expect(styledHeaderStub.callCount).to.equal(3);
expect(logStub.callCount).to.equal(6);
expect(tableStub.callCount).to.equal(3);
expect(styledHeaderStub.firstCall.args[0]).to.contain('Test Failures [2]');
expect(styledHeaderStub.secondCall.args[0]).to.contain('Test Success [1]');
expect(styledHeaderStub.thirdCall.args[0]).to.contain('Apex Code Coverage');
expect(styledHeaderStub.callCount).to.equal(4);
expect(logStub.callCount).to.equal(8);
expect(tableStub.callCount).to.equal(4);
expect(styledHeaderStub.args[0][0]).to.include('Component Failures [1]');
expect(styledHeaderStub.args[1][0]).to.include('Test Failures [2]');
expect(styledHeaderStub.args[2][0]).to.include('Test Success [1]');
expect(styledHeaderStub.args[3][0]).to.include('Apex Code Coverage');
});
});
});

0 comments on commit 99df1ca

Please sign in to comment.