Skip to content

Commit e15628f

Browse files
committed
add test for abort in theme environment
1 parent 6d14698 commit e15628f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/theme/src/cli/utilities/theme-environment/theme-environment.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {describe, expect, test, vi, beforeEach, afterEach} from 'vitest'
1111
import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
1212
import {createEvent} from 'h3'
1313
import * as output from '@shopify/cli-kit/node/output'
14+
import {fetchChecksums} from '@shopify/cli-kit/node/themes/api'
1415
import {IncomingMessage, ServerResponse} from 'node:http'
1516
import {Socket} from 'node:net'
1617

17-
vi.mock('@shopify/cli-kit/node/themes/api', () => ({fetchChecksums: () => Promise.resolve([])}))
18+
vi.mock('@shopify/cli-kit/node/themes/api', () => ({fetchChecksums: vi.fn(() => Promise.resolve([]))}))
1819
vi.mock('./remote-theme-watcher.js')
1920
vi.mock('./storefront-renderer.js')
2021
vi.spyOn(output, 'outputDebug')
@@ -187,6 +188,22 @@ describe('setupDevServer', () => {
187188
})
188189
})
189190

191+
test('should catch errors from fetchChecksums and reject backgroundJobPromise', async () => {
192+
// Given
193+
const context: DevServerContext = {
194+
...defaultServerContext,
195+
}
196+
const expectedError = new Error('Failed to fetch checksums from API')
197+
198+
vi.mocked(fetchChecksums).mockRejectedValueOnce(expectedError)
199+
200+
// When
201+
const {backgroundJobPromise} = setupDevServer(developmentTheme, context)
202+
203+
// Then
204+
await expect(backgroundJobPromise).rejects.toThrow('Failed to fetch checksums from API')
205+
})
206+
190207
describe('request handling', async () => {
191208
const context = {...defaultServerContext}
192209
const server = setupDevServer(developmentTheme, context)

packages/theme/src/cli/utilities/theme-environment/theme-environment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ function ensureThemeEnvironmentSetup(
6262
const abort = (error: Error): never => {
6363
renderThrownError('Failed to perform the initial theme synchronization.', error)
6464
rejectBackgroundJob(error)
65-
// Return a permanently pending promise to stop execution without throwing
65+
// Return a never-resolving promise to stop this promise chain without throwing.
66+
// Throwing would trigger catch handlers and continue execution. This stops the
67+
// chain while the error is handled through the separate backgroundJobPromise channel.
6668
return new Promise<never>(() => {}) as never
6769
}
6870

0 commit comments

Comments
 (0)