From 87284e102803e5b600b041b5a71e64b199d8e142 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sun, 5 Jul 2026 00:15:41 +0000 Subject: [PATCH] [Tests] Replace filesystem mocks in store execute result tests Refactor `packages/store/src/cli/services/store/execute/result.test.ts` to remove module-level filesystem mocks and use `inTemporaryDirectory` and `readFile` for actual filesystem operations. This adheres to the testing protocol of testing behavior over implementation details and avoiding filesystem mocks. --- .../cli/services/store/execute/result.test.ts | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/store/src/cli/services/store/execute/result.test.ts b/packages/store/src/cli/services/store/execute/result.test.ts index efc60970e66..fbb58b422f1 100644 --- a/packages/store/src/cli/services/store/execute/result.test.ts +++ b/packages/store/src/cli/services/store/execute/result.test.ts @@ -1,10 +1,10 @@ import {writeOrOutputStoreExecuteResult} from './result.js' import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest' -import {writeFile} from '@shopify/cli-kit/node/fs' +import {inTemporaryDirectory, readFile} from '@shopify/cli-kit/node/fs' +import {joinPath} from '@shopify/cli-kit/node/path' import {renderSuccess} from '@shopify/cli-kit/node/ui' import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output' -vi.mock('@shopify/cli-kit/node/fs') vi.mock('@shopify/cli-kit/node/ui') function captureStandardStreams() { @@ -42,12 +42,20 @@ describe('writeOrOutputStoreExecuteResult', () => { }) test('writes results to a file when outputFile is provided', async () => { - await writeOrOutputStoreExecuteResult({data: {shop: {name: 'Test shop'}}}, '/tmp/results.json') - - expect(writeFile).toHaveBeenCalledWith('/tmp/results.json', expect.stringContaining('Test shop')) - expect(renderSuccess).toHaveBeenCalledWith({ - headline: 'Operation succeeded.', - body: 'Results written to /tmp/results.json', + await inTemporaryDirectory(async (tmpDir) => { + // Given + const outputPath = joinPath(tmpDir, 'results.json') + + // When + await writeOrOutputStoreExecuteResult({data: {shop: {name: 'Test shop'}}}, outputPath) + + // Then + const content = await readFile(outputPath) + expect(content).toContain('Test shop') + expect(renderSuccess).toHaveBeenCalledWith({ + headline: 'Operation succeeded.', + body: `Results written to ${outputPath}`, + }) }) }) @@ -86,9 +94,17 @@ describe('writeOrOutputStoreExecuteResult', () => { }) test('suppresses success rendering when writing a file in json mode', async () => { - await writeOrOutputStoreExecuteResult({data: {shop: {name: 'Test shop'}}}, '/tmp/results.json', 'json') + await inTemporaryDirectory(async (tmpDir) => { + // Given + const outputPath = joinPath(tmpDir, 'results.json') - expect(writeFile).toHaveBeenCalledWith('/tmp/results.json', expect.stringContaining('Test shop')) - expect(renderSuccess).not.toHaveBeenCalled() + // When + await writeOrOutputStoreExecuteResult({data: {shop: {name: 'Test shop'}}}, outputPath, 'json') + + // Then + const content = await readFile(outputPath) + expect(content).toContain('Test shop') + expect(renderSuccess).not.toHaveBeenCalled() + }) }) })