Skip to content

Commit 1408474

Browse files
committed
add warning and prompt for user to confirm before executing theme dr test suite
1 parent 18a9b6d commit 1408474

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli': patch
3+
---
4+
5+
add warning and confirm with user before running theme doctor test suite
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import DoctorTheme from './index.js'
2+
import {runThemeDoctor} from '../../../services/doctor/theme/runner.js'
3+
import {renderConfirmationPrompt} from '@shopify/cli-kit/node/ui'
4+
import {test, expect, vi} from 'vitest'
5+
6+
vi.mock('@shopify/cli-kit/node/ui')
7+
vi.mock('../../../services/doctor/theme/runner.js')
8+
9+
test('does not run theme doctor when user cancels', async () => {
10+
// Given
11+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)
12+
13+
// When
14+
await DoctorTheme.run(['--environment', 'test'])
15+
16+
// Then
17+
expect(runThemeDoctor).not.toHaveBeenCalled()
18+
})
19+
20+
test('runs theme doctor when user confirms', async () => {
21+
// Given
22+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
23+
vi.mocked(runThemeDoctor).mockResolvedValue([])
24+
25+
// When
26+
await DoctorTheme.run(['--environment', 'test'])
27+
28+
// Then
29+
expect(runThemeDoctor).toHaveBeenCalled()
30+
})

packages/cli/src/cli/commands/doctor/theme/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Command from '@shopify/cli-kit/node/base-command'
33
import {globalFlags} from '@shopify/cli-kit/node/cli'
44
import {Flags} from '@oclif/core'
55
import {resolvePath, cwd} from '@shopify/cli-kit/node/path'
6+
import {renderConfirmationPrompt, RenderConfirmationPromptOptions} from '@shopify/cli-kit/node/ui'
67

78
export default class DoctorTheme extends Command {
89
static description = 'Run all theme command doctor tests'
@@ -36,6 +37,16 @@ export default class DoctorTheme extends Command {
3637

3738
async run(): Promise<void> {
3839
const {flags} = await this.parse(DoctorTheme)
40+
const promptOptions: RenderConfirmationPromptOptions = {
41+
message: `This command will call theme commands that will interact with your remote shop. Please confirm before running.`,
42+
confirmationMessage: 'Yes I understand',
43+
cancellationMessage: 'No, cancel the command',
44+
}
45+
const confirmed = await renderConfirmationPrompt(promptOptions)
46+
47+
if (!confirmed) {
48+
return
49+
}
3950

4051
const results = await runThemeDoctor({
4152
path: flags.path,

0 commit comments

Comments
 (0)