From 5f84c489f3365df71a6bc89fe7cdfa3129b38dc4 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 24 Feb 2023 10:51:11 -0700 Subject: [PATCH] fix: add logJson stub --- src/sfCommand.ts | 16 ++++++++-------- src/stubUx.ts | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sfCommand.ts b/src/sfCommand.ts index cf460eae..660d3300 100644 --- a/src/sfCommand.ts +++ b/src/sfCommand.ts @@ -308,6 +308,14 @@ export abstract class SfCommand 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. * @@ -410,14 +418,6 @@ export abstract class SfCommand 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 { try { diff --git a/src/stubUx.ts b/src/stubUx.ts index 73f11087..88cab99c 100644 --- a/src/stubUx.ts +++ b/src/stubUx.ts @@ -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'),