Skip to content

Commit 3793022

Browse files
committed
Move tests to their proper location
1 parent 9f10bdf commit 3793022

File tree

2 files changed

+63
-57
lines changed

2 files changed

+63
-57
lines changed

packages/theme/src/cli/services/dev.test.ts

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {openURLSafely, renderLinks} from './dev.js'
2-
import {ensureLiveThemeConfirmed} from '../utilities/theme-ui.js'
32
import {describe, expect, test, vi} from 'vitest'
43
import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
5-
import {DEVELOPMENT_THEME_ROLE, LIVE_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
6-
import {renderConfirmationPrompt, renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
4+
import {DEVELOPMENT_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
5+
import {renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
76
import {openURL} from '@shopify/cli-kit/node/system'
87

98
vi.mock('@shopify/cli-kit/node/ui')
@@ -18,11 +17,10 @@ vi.mock('@shopify/cli-kit/node/system', () => ({
1817
openURL: vi.fn(),
1918
}))
2019

21-
describe('dev', () => {
22-
const store = 'my-store.myshopify.com'
23-
const theme = buildTheme({id: 123, name: 'My Theme', role: DEVELOPMENT_THEME_ROLE})!
24-
const liveTheme = buildTheme({id: 123, name: 'My Theme', role: LIVE_THEME_ROLE})!
20+
const store = 'my-store.myshopify.com'
21+
const theme = buildTheme({id: 123, name: 'My Theme', role: DEVELOPMENT_THEME_ROLE})!
2522

23+
describe('renderLinks', () => {
2624
test('renders "dev" command links', async () => {
2725
// Given
2826
const themeId = theme.id.toString()
@@ -85,57 +83,22 @@ describe('dev', () => {
8583
],
8684
})
8785
})
88-
describe('openURLSafely', () => {
89-
test('calls renderWarning when openURL fails', async () => {
90-
// Given
91-
const error = new Error('Failed to open URL')
92-
vi.mocked(openURL).mockRejectedValueOnce(error)
93-
94-
// When
95-
openURLSafely('http://127.0.0.1:9292', 'localhost')
96-
97-
// Then
98-
await vi.waitFor(() => {
99-
expect(renderWarning).toHaveBeenCalledWith({
100-
headline: 'Failed to open localhost.',
101-
body: error.stack ?? error.message,
102-
})
103-
})
104-
})
105-
})
106-
describe('ensureLiveThemeConfirmed', () => {
107-
vi.stubGlobal('process', {...process, stdout: {...process.stdout, isTTY: true}})
108-
109-
test('prompts for confirmation if acting on a live theme', async () => {
110-
// Given
111-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
86+
})
87+
describe('openURLSafely', () => {
88+
test('calls renderWarning when openURL fails', async () => {
89+
// Given
90+
const error = new Error('Failed to open URL')
91+
vi.mocked(openURL).mockRejectedValueOnce(error)
11292

113-
const result = await ensureLiveThemeConfirmed(liveTheme, 'start development mode', false)
93+
// When
94+
openURLSafely('http://127.0.0.1:9292', 'localhost')
11495

115-
// Then
116-
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
117-
message:
118-
'You\'re about to start development mode on your live theme "My Theme". This will make changes visible to customers. Are you sure you want to proceed?',
119-
confirmationMessage: 'Yes, proceed with live theme',
120-
cancellationMessage: 'No, cancel',
96+
// Then
97+
await vi.waitFor(() => {
98+
expect(renderWarning).toHaveBeenCalledWith({
99+
headline: 'Failed to open localhost.',
100+
body: error.stack ?? error.message,
121101
})
122-
expect(result).toBe(true)
123-
})
124-
125-
test('does not prompt for confirmation if acting on a non-live theme', async () => {
126-
// Given
127-
await ensureLiveThemeConfirmed(theme, 'start development mode', false)
128-
129-
// Then
130-
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
131-
})
132-
133-
test('does not prompt for confirmation if acting on a live theme and allowLive flag is true', async () => {
134-
// Given
135-
await ensureLiveThemeConfirmed(liveTheme, 'start development mode', true)
136-
137-
// Then
138-
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
139102
})
140103
})
141104
})

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import {themeComponent, themesComponent, ensureDirectoryConfirmed} from './theme-ui.js'
1+
import {themeComponent, themesComponent, ensureDirectoryConfirmed, ensureLiveThemeConfirmed} from './theme-ui.js'
22
import {Theme} from '@shopify/cli-kit/node/themes/types'
33
import {renderConfirmationPrompt, renderError, renderWarning} from '@shopify/cli-kit/node/ui'
4-
import {test, describe, expect, vi} from 'vitest'
4+
import {test, describe, expect, vi, beforeEach} from 'vitest'
5+
import {DEVELOPMENT_THEME_ROLE, LIVE_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
6+
import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
57

68
vi.mock('@shopify/cli-kit/node/ui')
79

@@ -69,6 +71,47 @@ describe('ensureDirectoryConfirmed', () => {
6971
})
7072
})
7173

74+
describe('ensureLiveThemeConfirmed', () => {
75+
const theme = buildTheme({id: 123, name: 'My Theme', role: DEVELOPMENT_THEME_ROLE})!
76+
const liveTheme = buildTheme({id: 123, name: 'My Theme', role: LIVE_THEME_ROLE})!
77+
78+
beforeEach(() => {
79+
vi.stubGlobal('process', {...process, stdout: {...process.stdout, isTTY: true}})
80+
})
81+
82+
test('prompts for confirmation if acting on a live theme', async () => {
83+
// Given
84+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
85+
86+
const result = await ensureLiveThemeConfirmed(liveTheme, 'start development mode', false)
87+
88+
// Then
89+
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
90+
message:
91+
'You\'re about to start development mode on your live theme "My Theme". This will make changes visible to customers. Are you sure you want to proceed?',
92+
confirmationMessage: 'Yes, proceed with live theme',
93+
cancellationMessage: 'No, cancel',
94+
})
95+
expect(result).toBe(true)
96+
})
97+
98+
test('does not prompt for confirmation if acting on a non-live theme', async () => {
99+
// Given
100+
await ensureLiveThemeConfirmed(theme, 'start development mode', false)
101+
102+
// Then
103+
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
104+
})
105+
106+
test('does not prompt for confirmation if acting on a live theme and allowLive flag is true', async () => {
107+
// Given
108+
await ensureLiveThemeConfirmed(liveTheme, 'start development mode', true)
109+
110+
// Then
111+
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
112+
})
113+
})
114+
72115
function theme(id: number) {
73116
return {id, name: `theme ${id}`} as Theme
74117
}

0 commit comments

Comments
 (0)