diff --git a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts index b37df137..0e43eb5f 100644 --- a/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts +++ b/packages/cli/src/lib/commands/collect/utils/persist/open-report.unit.test.ts @@ -3,7 +3,11 @@ import { handleOpenFlowReports, openFlowReports } from './open-report'; import { logVerbose } from '../../../../core/loggin'; import { CollectCommandOptions } from '../../options'; +jest.mock('open'); +jest.mock('../../../../core/loggin'); + describe('handleOpenFlowReport', () => { + beforeEach(() => { jest.clearAllMocks(); }) @@ -14,7 +18,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: false, } as CollectCommandOptions); - expect(typeof openReportsProcess).toEqual("function"); + expect(openReportsProcess).toEqual(expect.any(Function)); }); it('should return undefined if openReport is false', () => { @@ -23,7 +27,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: false, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); it('should return undefined if dryRun is true', () => { @@ -32,7 +36,7 @@ describe('handleOpenFlowReport', () => { interactive: true, dryRun: true, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); it('should return undefined if interactive is false', () => { @@ -41,15 +45,10 @@ describe('handleOpenFlowReport', () => { interactive: false, dryRun: false, } as CollectCommandOptions); - expect(openReportsProcess).toEqual(undefined); + expect(openReportsProcess).toBeUndefined(); }); - - }); -jest.mock('open'); -jest.mock('../../../../core/loggin'); - describe('openReports', () => { beforeEach(() => { @@ -61,48 +60,18 @@ describe('openReports', () => { expect(openReport).not.toHaveBeenCalled(); }); - it('should not logVerbose if no file name is passed', async () => { - await openFlowReports([]); - expect(logVerbose).not.toHaveBeenCalled(); - }); - - it('should open the report if filenames includes an html report', async () => { - await openFlowReports(['example.html']); - expect(openReport).toHaveBeenCalled(); - }); - - it('should logVerbose if filenames includes an html report', async () => { - await openFlowReports(['example.html']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('HTML')); - }); - - it('should open the report if filenames includes a json report', async () => { - await openFlowReports(['example.json']); + it.each(['html', 'json', 'md'])('should open the %s report', async (format) => { + await openFlowReports([`example.${format}`]); expect(openReport).toHaveBeenCalled(); }); - it('should logVerbose if filenames includes an json report', async () => { - await openFlowReports(['example.json']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('JSON')); - }); - - it('should open the report if filenames includes a md report', async () => { - await openFlowReports(['example.md']); - expect(openReport).toHaveBeenCalled(); - }); - - it('should logVerbose if filenames includes an md report', async () => { - await openFlowReports(['example.md']); - expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining('Markdown')); + it('should not logVerbose if no file name is passed', async () => { + await openFlowReports([]); + expect(logVerbose).not.toHaveBeenCalled(); }); it('should only open 1 time report if multiple report formats are passed', async () => { await openFlowReports(['example.html', 'example.json', 'example.md']); expect(openReport).toHaveBeenCalledTimes(1); }); - - it('should only logVerbose 1 time report if multiple report formats are passed', async () => { - await openFlowReports(['example.html', 'example.json', 'example.md']); - expect(logVerbose).toHaveBeenCalledTimes(1); - }); }); diff --git a/packages/cli/src/lib/commands/init/utils.ts b/packages/cli/src/lib/commands/init/utils.ts index ac8f10ab..7f911186 100644 --- a/packages/cli/src/lib/commands/init/utils.ts +++ b/packages/cli/src/lib/commands/init/utils.ts @@ -5,7 +5,7 @@ import { REPORT_FORMAT_VALUES } from '../collect/constants'; const isValidFormat = (value: any): value is ReportFormat => REPORT_FORMAT_VALUES.includes(value); -function sanitizedFormats(formats: string[]): ReportFormat[] { +function sanitizedFormats(formats: string[]) { const validatedFormats: ReportFormat[] = formats.filter(isValidFormat); if (validatedFormats.length !== formats.length) { throw new Error(`${formats} contains invalid format options`);