From 963333d62ea412ab347eaf48151bd703404af126 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:35:39 +0000 Subject: [PATCH] [Tests] Remove filesystem mocks in doc fetch service tests Refactored `packages/cli/src/cli/services/commands/doc/fetch.test.ts` to replace filesystem mocks with real operations using `inTemporaryDirectory`. Verified that `docFetchService` correctly handles directory creation and file writing by asserting the state of the real filesystem. - Replaced `vi.mock('@shopify/cli-kit/node/fs')` with real fs utilities. - Updated 'writes the document to the output path instead of stdout' to use `inTemporaryDirectory`. - Complied with `vitest/prefer-expect-resolves` ESLint rule. --- .../cli/services/commands/doc/fetch.test.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/cli/services/commands/doc/fetch.test.ts b/packages/cli/src/cli/services/commands/doc/fetch.test.ts index 8406cbe9ba9..bebf2951d2c 100644 --- a/packages/cli/src/cli/services/commands/doc/fetch.test.ts +++ b/packages/cli/src/cli/services/commands/doc/fetch.test.ts @@ -3,12 +3,11 @@ import {describe, expect, test, vi, beforeEach} from 'vitest' import {fetch} from '@shopify/cli-kit/node/http' import {outputResult} from '@shopify/cli-kit/node/output' import {AbortError} from '@shopify/cli-kit/node/error' -import {mkdir, writeFile} from '@shopify/cli-kit/node/fs' -import {dirname, resolvePath} from '@shopify/cli-kit/node/path' +import {inTemporaryDirectory, readFile, fileExistsSync} from '@shopify/cli-kit/node/fs' +import {joinPath} from '@shopify/cli-kit/node/path' vi.mock('@shopify/cli-kit/node/http') vi.mock('@shopify/cli-kit/node/output') -vi.mock('@shopify/cli-kit/node/fs') const okResponse = (body: string) => ({ok: true, status: 200, statusText: 'OK', text: () => Promise.resolve(body)}) as any @@ -44,12 +43,18 @@ describe('docFetchService', () => { }) test('writes the document to the output path instead of stdout', async () => { - await docFetchService('https://shopify.dev/docs/api/shopify-cli', 'docs/shopify-cli.md') + await inTemporaryDirectory(async (tmpDir) => { + // Given + const outputPath = joinPath(tmpDir, 'docs/shopify-cli.md') - const expectedPath = resolvePath('docs/shopify-cli.md') - expect(mkdir).toHaveBeenCalledWith(dirname(expectedPath)) - expect(writeFile).toHaveBeenCalledWith(expectedPath, '# Doc') - expect(outputResult).not.toHaveBeenCalled() + // When + await docFetchService('https://shopify.dev/docs/api/shopify-cli', outputPath) + + // Then + expect(fileExistsSync(outputPath)).toBe(true) + await expect(readFile(outputPath)).resolves.toBe('# Doc') + expect(outputResult).not.toHaveBeenCalled() + }) }) test('throws when the response is not ok', async () => {