diff --git a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts index 06da50cf..4b7105b9 100644 --- a/packages/cli/src/lib/commands/collect/processes/collect-reports.ts +++ b/packages/cli/src/lib/commands/collect/processes/collect-reports.ts @@ -5,7 +5,7 @@ import { persistFlow } from '../utils/persist/persist-flow'; import { handleOpenFlowReports } from '../utils/persist/open-report'; import { RcJson } from '../../../types'; -export async function collectReports(cfg: RcJson, openReport: boolean): Promise { +export async function collectReports(cfg: RcJson, openReport?: boolean): Promise { const { collect, persist, assert } = cfg; diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts index 55fd2cb0..5d96f774 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.ts @@ -27,7 +27,7 @@ export async function openFlowReports(fileNames: string[]): Promise { return Promise.resolve(void 0); } -export function handleOpenFlowReports(openReport: boolean): typeof openFlowReports | undefined { +export function handleOpenFlowReports(openReport?: boolean): typeof openFlowReports | undefined { if (dryRun() || !openReport || !interactive()) { return; } diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index c219ec9b..ac8f10ab 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -1,6 +1,17 @@ -import { CollectRcOptions, PersistRcOptions } from '../collect/options/types'; +import { CollectRcOptions, PersistRcOptions, ReportFormat } from '../collect/options/types'; import { InitOptions } from './options'; import { AssertRcOptions } from '../assert/options'; +import { REPORT_FORMAT_VALUES } from '../collect/constants'; + +const isValidFormat = (value: any): value is ReportFormat => REPORT_FORMAT_VALUES.includes(value); + +function sanitizedFormats(formats: string[]): ReportFormat[] { + const validatedFormats: ReportFormat[] = formats.filter(isValidFormat); + if (validatedFormats.length !== formats.length) { + throw new Error(`${formats} contains invalid format options`); + } + return validatedFormats; +} export function getInitCommandOptionsFromArgv(argv: InitOptions) { let { @@ -18,7 +29,7 @@ export function getInitCommandOptionsFromArgv(argv: InitOptions) { let persist = {} as PersistRcOptions; outPath && (persist.outPath = outPath); - format && (persist.format = format); + format && (persist.format = sanitizedFormats(format)); let assert = {} as AssertRcOptions; budgetPath && (assert.budgetPath = budgetPath); diff --git a/packages/cli/src/lib/pre-set.ts b/packages/cli/src/lib/pre-set.ts index 88c5bb1a..2be7d1d3 100644 --- a/packages/cli/src/lib/pre-set.ts +++ b/packages/cli/src/lib/pre-set.ts @@ -1,5 +1,5 @@ import { ArgvPreset } from './types'; -import { detectCliMode } from './global/cli-mode/cli-mode'; +import { detectCliMode } from './global/cli-mode'; import { DEFAULT_FULL_RC_PATH } from './constants'; export const DEFAULT_PRESET: ArgvPreset = {