generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
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: deploy errors are reported properly #146
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { Logger } from '@salesforce/core'; | ||
import { UX } from '@salesforce/command'; | ||
import { stubInterface } from '@salesforce/ts-sinon'; | ||
import { getDeployResult } from '../commands/source/deployResponses'; | ||
import { DeployCommandResult, DeployResultFormatter } from '../../src/formatters/deployResultFormatter'; | ||
|
||
describe('DeployResultFormatter', () => { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
const deployResultSuccess = getDeployResult('successSync'); | ||
const deployResultFailure = getDeployResult('failed'); | ||
|
||
const logger = Logger.childFromRoot('deployTestLogger').useMemoryLogging(); | ||
let ux; | ||
let logStub: sinon.SinonStub; | ||
let styledHeaderStub: sinon.SinonStub; | ||
let tableStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
logStub = sandbox.stub(); | ||
styledHeaderStub = sandbox.stub(); | ||
tableStub = sandbox.stub(); | ||
ux = stubInterface<UX>(sandbox, { | ||
log: logStub, | ||
styledHeader: styledHeaderStub, | ||
table: tableStub, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('getJson', () => { | ||
it('should return expected json for a success', async () => { | ||
const deployResponse = JSON.parse(JSON.stringify(deployResultSuccess.response)) as DeployCommandResult; | ||
const expectedSuccessResults = deployResultSuccess.response as DeployCommandResult; | ||
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultSuccess); | ||
const json = formatter.getJson(); | ||
|
||
expectedSuccessResults.deployedSource = deployResultSuccess.getFileResponses(); | ||
expectedSuccessResults.outboundFiles = []; | ||
expectedSuccessResults.deploys = [deployResponse]; | ||
expect(json).to.deep.equal(expectedSuccessResults); | ||
}); | ||
|
||
it('should return expected json for a failure', async () => { | ||
const deployResponse = JSON.parse(JSON.stringify(deployResultFailure.response)) as DeployCommandResult; | ||
const expectedFailureResults = deployResultFailure.response as DeployCommandResult; | ||
expectedFailureResults.deployedSource = deployResultFailure.getFileResponses(); | ||
expectedFailureResults.outboundFiles = []; | ||
expectedFailureResults.deploys = [deployResponse]; | ||
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultFailure); | ||
expect(formatter.getJson()).to.deep.equal(expectedFailureResults); | ||
}); | ||
}); | ||
|
||
describe('display', () => { | ||
it('should output as expected for a success', async () => { | ||
const formatter = new DeployResultFormatter(logger, ux, {}, deployResultSuccess); | ||
formatter.display(); | ||
expect(styledHeaderStub.calledOnce).to.equal(true); | ||
expect(logStub.calledOnce).to.equal(true); | ||
expect(tableStub.called).to.equal(true); | ||
expect(styledHeaderStub.firstCall.args[0]).to.contain('Deployed Source'); | ||
const fileResponses = deployResultSuccess.getFileResponses(); | ||
expect(tableStub.firstCall.args[0]).to.deep.equal(fileResponses); | ||
}); | ||
|
||
it('should output as expected for a failure', 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]'); | ||
const fileResponses = deployResultFailure.getFileResponses(); | ||
expect(tableStub.firstCall.args[0]).to.deep.equal(fileResponses); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth a comment as to why the parse/stringify is required