-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate that generate path points to a valid theme directories
- Loading branch information
1 parent
30eb0d9
commit c66bc35
Showing
7 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/theme/src/cli/commands/theme/generate/block.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import GenerateBlock from './block.js' | ||
import {hasRequiredThemeDirectories} from '../../../utilities/theme-fs.js' | ||
import {describe, expect, test, vi} from 'vitest' | ||
import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
import {cwd} from '@shopify/cli-kit/node/path' | ||
|
||
vi.mock('../../../utilities/theme-fs.js') | ||
vi.mock('@shopify/cli-kit/node/ui') | ||
|
||
describe('GenerateBlock', () => { | ||
const path = cwd() | ||
test('validates theme directory structure by default', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateBlock.run(['--path', path]) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).toHaveBeenCalledWith(path) | ||
expect(renderWarning).toHaveBeenCalledWith({ | ||
body: [ | ||
'The current directory does not contain the required theme directories (config, layout, sections, templates).', | ||
], | ||
}) | ||
}) | ||
|
||
test('skips directory validation when force flag is used', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateBlock.run(['--path', path, '--force']) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).not.toHaveBeenCalled() | ||
expect(renderWarning).not.toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/theme/src/cli/commands/theme/generate/section.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import GenerateSection from './section.js' | ||
import {hasRequiredThemeDirectories} from '../../../utilities/theme-fs.js' | ||
import {describe, expect, test, vi} from 'vitest' | ||
import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
import {cwd} from '@shopify/cli-kit/node/path' | ||
|
||
vi.mock('../../../utilities/theme-fs.js') | ||
vi.mock('@shopify/cli-kit/node/ui') | ||
|
||
describe('GenerateSection', () => { | ||
const path = cwd() | ||
test('validates theme directory structure by default', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateSection.run(['--path', path]) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).toHaveBeenCalledWith(path) | ||
expect(renderWarning).toHaveBeenCalledWith({ | ||
body: [ | ||
'The current directory does not contain the required theme directories (config, layout, sections, templates).', | ||
], | ||
}) | ||
}) | ||
|
||
test('skips directory validation when force flag is used', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateSection.run(['--path', path, '--force']) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).not.toHaveBeenCalled() | ||
expect(renderWarning).not.toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/theme/src/cli/commands/theme/generate/template.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import GenerateTemplate from './template.js' | ||
import {hasRequiredThemeDirectories} from '../../../utilities/theme-fs.js' | ||
import {describe, expect, test, vi} from 'vitest' | ||
import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
import {cwd} from '@shopify/cli-kit/node/path' | ||
|
||
vi.mock('../../../utilities/theme-fs.js') | ||
vi.mock('@shopify/cli-kit/node/ui') | ||
|
||
describe('GenerateTemplate', () => { | ||
const path = cwd() | ||
test('validates theme directory structure by default', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateTemplate.run(['--path', path]) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).toHaveBeenCalledWith(path) | ||
expect(renderWarning).toHaveBeenCalledWith({ | ||
body: [ | ||
'The current directory does not contain the required theme directories (config, layout, sections, templates).', | ||
], | ||
}) | ||
}) | ||
|
||
test('skips directory validation when force flag is used', async () => { | ||
// Given | ||
vi.mocked(hasRequiredThemeDirectories).mockResolvedValue(false) | ||
|
||
// When | ||
await GenerateTemplate.run(['--path', path, '--force']) | ||
|
||
// Then | ||
expect(hasRequiredThemeDirectories).not.toHaveBeenCalled() | ||
expect(renderWarning).not.toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters