Skip to content

Commit

Permalink
fix: add logJson stub
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Feb 24, 2023
1 parent f23395e commit 5f84c48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ export abstract class SfCommand<T> extends Command {
this.ux.styledHeader(text);
}

// eslint-disable-next-line class-methods-use-this
public logJson(json: AnyJson | unknown): void {
// If `--json` is enabled, then the ux instance on the class will disable output, which
// means that the logJson method will not output anything. So, we need to create a new
// instance of the ux class that does not have output disabled in order to log the json.
new Ux().styledJSON(json as AnyJson);
}

/**
* Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
*
Expand Down Expand Up @@ -410,14 +418,6 @@ export abstract class SfCommand<T> extends Command {
};
}

// eslint-disable-next-line class-methods-use-this
protected logJson(json: AnyJson | unknown): void {
// If `--json` is enabled, then the ux instance on the class will disable output, which
// means that the logJson method will not output anything. So, we need to create a new
// instance of the ux class that does not have output disabled in order to log the json.
new Ux().styledJSON(json as AnyJson);
}

// eslint-disable-next-line class-methods-use-this
protected async assignProject(): Promise<SfProject> {
try {
Expand Down
1 change: 1 addition & 0 deletions src/stubUx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function stubUx(sandbox: SinonSandbox) {
export function stubSfCommandUx(sandbox: SinonSandbox) {
return {
log: sandbox.stub(SfCommand.prototype, 'log'),
logJson: sandbox.stub(SfCommand.prototype, 'logJson'),
logToStderr: sandbox.stub(SfCommand.prototype, 'logToStderr'),
logSuccess: sandbox.stub(SfCommand.prototype, 'logSuccess'),
logSensitive: sandbox.stub(SfCommand.prototype, 'logSensitive'),
Expand Down

0 comments on commit 5f84c48

Please sign in to comment.