Skip to content

Commit da213c0

Browse files
chore: mocked fs operations for generate arazzo tests (#2336)
1 parent c3d9b58 commit da213c0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/cli/src/__tests__/commands/generate-arazzo.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { GenerateArazzoCommandArgv, handleGenerateArazzo } from '../../commands/
22
import { generate } from '@redocly/respect-core';
33
import { vi, describe, it, expect, beforeEach } from 'vitest';
44
import * as openapiCore from '@redocly/openapi-core';
5+
import { writeFileSync } from 'node:fs';
56

67
vi.mock('@redocly/respect-core', async () => {
78
const actual = await vi.importActual<typeof import('@redocly/respect-core')>(
@@ -24,6 +25,11 @@ vi.mock('@redocly/openapi-core', async () => {
2425
};
2526
});
2627

28+
vi.mock('node:fs', () => ({
29+
writeFileSync: vi.fn(),
30+
existsSync: vi.fn(() => false),
31+
}));
32+
2733
describe('handleGenerateArazzo', () => {
2834
beforeEach(() => {
2935
vi.clearAllMocks();
@@ -50,6 +56,7 @@ describe('handleGenerateArazzo', () => {
5056
version: '1.0.0',
5157
config: mockConfig,
5258
});
59+
expect(writeFileSync).toHaveBeenCalledWith('auto-generated.arazzo.yaml', 'mocked yaml');
5360
});
5461

5562
it('should use custom output file when provided', async () => {
@@ -73,6 +80,8 @@ describe('handleGenerateArazzo', () => {
7380
version: '1.0.0',
7481
config: mockConfig,
7582
});
83+
84+
expect(writeFileSync).toHaveBeenCalledWith('custom.arazzo.yaml', 'mocked yaml');
7685
});
7786

7887
it('should throw an error if the openapi file is not valid', async () => {
@@ -91,5 +100,6 @@ describe('handleGenerateArazzo', () => {
91100
await expect(handleGenerateArazzo(commandArgs)).rejects.toThrow(
92101
'❌ Failed to generate Arazzo description. Check the output file path you provided, or the OpenAPI file content.'
93102
);
103+
expect(writeFileSync).not.toHaveBeenCalled();
94104
});
95105
});

0 commit comments

Comments
 (0)