Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-corners-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

add warning and confirm with user before running theme doctor test suite
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import DoctorReleaseTheme from './index.js'
import {runThemeDoctor} from '../../../services/doctor-release/theme/runner.js'
import {renderConfirmationPrompt} from '@shopify/cli-kit/node/ui'
import {afterEach, expect, test, vi} from 'vitest'

vi.mock('@shopify/cli-kit/node/ui')
vi.mock('../../../services/doctor-release/theme/runner.js')

afterEach(() => {
vi.unstubAllEnvs()
})

test('does not run theme doctor when user cancels', async () => {
// Given
vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1')
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)

// When
await DoctorReleaseTheme.run(['--environment', 'test'])

// Then
expect(runThemeDoctor).not.toHaveBeenCalled()
})

test('runs theme doctor when user confirms', async () => {
// Given
vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1')
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
vi.mocked(runThemeDoctor).mockResolvedValue([])

// When
await DoctorReleaseTheme.run(['--environment', 'test'])

// Then
expect(runThemeDoctor).toHaveBeenCalled()
})

test('does not run theme doctor when environment variable is not set', async () => {
// Given - no SHOPIFY_CLI_DOCTOR env var set

// When
await DoctorReleaseTheme.run(['--environment', 'test'])

// Then - neither prompt nor doctor should be called
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
expect(runThemeDoctor).not.toHaveBeenCalled()
})
10 changes: 10 additions & 0 deletions packages/cli/src/cli/commands/doctor-release/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {globalFlags} from '@shopify/cli-kit/node/cli'
import {Flags} from '@oclif/core'
import {resolvePath, cwd} from '@shopify/cli-kit/node/path'
import {canRunDoctorRelease} from '@shopify/cli-kit/node/context/local'
import {renderConfirmationPrompt, RenderConfirmationPromptOptions} from '@shopify/cli-kit/node/ui'

export default class DoctorReleaseTheme extends Command {
static description = 'Run all theme command doctor-release tests'
Expand Down Expand Up @@ -39,7 +40,16 @@ export default class DoctorReleaseTheme extends Command {
if (!canRunDoctorRelease()) {
return
}
const promptOptions: RenderConfirmationPromptOptions = {
message: `This will run automated theme commands against your shop. It will modify remote themes. Please confirm before running.`,
confirmationMessage: 'Yes I understand',
cancellationMessage: 'No, cancel the command',
}
const confirmed = await renderConfirmationPrompt(promptOptions)

if (!confirmed) {
return
}
const {flags} = await this.parse(DoctorReleaseTheme)

const results = await runThemeDoctor({
Expand Down
Loading