File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
packages/cli/src/cli/commands/doctor/theme Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @shopify/cli ' : patch
3+ ---
4+
5+ add warning and confirm with user before running theme doctor test suite
Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Command from '@shopify/cli-kit/node/base-command'
33import { globalFlags } from '@shopify/cli-kit/node/cli'
44import { Flags } from '@oclif/core'
55import { resolvePath , cwd } from '@shopify/cli-kit/node/path'
6+ import { renderConfirmationPrompt , RenderConfirmationPromptOptions } from '@shopify/cli-kit/node/ui'
67
78export 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 ,
You can’t perform that action at this time.
0 commit comments