Skip to content

Commit 76511b7

Browse files
test: simplify test
1 parent 6ceca43 commit 76511b7

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/cli/src/lib/commands/collect/utils/persist/persist-flow.unit.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as utils from './utils';
2-
import * as reportUtils from '../report/utils';
3-
import * as mdReportUtils from '../../../assert/utils/md-report';
1+
import { generateStdoutReport } from './utils';
2+
import { createReducedReport } from '../report/utils';
3+
import { generateMdReport } from '../../../assert/utils/md-report';
44
import { persistFlow } from './persist-flow';
55
import { writeFile } from '../../../../core/file';
66
import { log } from '../../../../core/loggin';
7-
import { ReducedReport } from '../report/types';
87

9-
import { UserFlow } from '../../../../hacky-things/lighthouse';
8+
import type { ReducedReport } from '../report/types';
9+
import type { UserFlow } from '../../../../hacky-things/lighthouse';
1010

1111
jest.mock('node:fs', () => ({
1212
existsSync: jest.fn().mockReturnValue(true)
@@ -15,7 +15,9 @@ jest.mock('../../../../hacky-things/lighthouse')
1515
jest.mock('../../../../core/file');
1616
jest.mock('../../../../core/loggin');
1717
jest.mock('./utils');
18-
jest.mock('../../../assert/utils/md-report');
18+
jest.mock('../../../assert/utils/md-report', () => ({
19+
generateMdReport: jest.fn().mockReturnValue('Mock Md Report')
20+
}));
1921
jest.mock('../report/utils', () => ({
2022
createReducedReport: jest.fn(),
2123
toReportName: jest.fn().mockReturnValue('report'),
@@ -49,7 +51,7 @@ describe('persist flow reports in specified format', () => {
4951
});
5052

5153
it('should log a report if stdout is passed as format', async () => {
52-
const generateStdoutReportSpy = jest.spyOn(utils, 'generateStdoutReport').mockReturnValue('Mock stdout report')
54+
const generateStdoutReportSpy = jest.mocked(generateStdoutReport).mockReturnValue('Mock stdout report')
5355
await persistFlow(flow, { outPath: '', format: ['stdout'], url: 'mock.com' });
5456
expect(generateStdoutReportSpy).toHaveBeenCalled();
5557
expect(log).toHaveBeenCalledWith('Mock stdout report');
@@ -91,15 +93,14 @@ describe('persist flow reports in specified format', () => {
9193

9294
it('should extract an md report from the json report if md is given as format', async () => {
9395
jest.spyOn(flow, 'createFlowResult').mockResolvedValue({mock: 'base for md report'});
94-
const createReducedReportSpy = jest.spyOn(reportUtils, 'createReducedReport').mockReturnValue({mock: 'reduced report'} as any as ReducedReport);
95-
const generateMdReportSpy = jest.spyOn(mdReportUtils, 'generateMdReport');
96+
const createReducedReportSpy = jest.mocked(createReducedReport).mockReturnValue({mock: 'reduced report'} as any as ReducedReport);
97+
const generateMdReportMock = jest.mocked(generateMdReport);
9698
await persistFlow(flow, { outPath: '', format: ['md'], url: 'mock.com' });
9799
expect(createReducedReportSpy).toHaveBeenCalledWith({mock: 'base for md report'})
98-
expect(generateMdReportSpy).toHaveBeenCalledWith({mock: 'reduced report'});
100+
expect(generateMdReportMock).toHaveBeenCalledWith({mock: 'reduced report'});
99101
});
100102

101103
it('should save the report in md if md is given as format', async () => {
102-
jest.spyOn(mdReportUtils, 'generateMdReport').mockReturnValue('Mock Md Report')
103104
await persistFlow(flow, { outPath: '', format: ['md'], url: 'mock.com' });
104105
expect(writeFile).toHaveBeenCalledWith('report.md', 'Mock Md Report');
105106
});

0 commit comments

Comments
 (0)