|
1 | 1 | import spec from './app_config_hosted_app_home.js' |
2 | 2 | import {placeholderAppConfiguration} from '../../app/app.test-data.js' |
3 | | -import {copyDirectoryContents} from '@shopify/cli-kit/node/fs' |
4 | | -import {describe, expect, test, vi} from 'vitest' |
5 | | - |
6 | | -vi.mock('@shopify/cli-kit/node/fs') |
| 3 | +import {describe, expect, test} from 'vitest' |
7 | 4 |
|
8 | 5 | describe('hosted_app_home', () => { |
9 | 6 | describe('transform', () => { |
@@ -54,43 +51,43 @@ describe('hosted_app_home', () => { |
54 | 51 | }) |
55 | 52 | }) |
56 | 53 |
|
57 | | - describe('copyStaticAssets', () => { |
58 | | - test('should copy static assets from source to output directory', async () => { |
59 | | - vi.mocked(copyDirectoryContents).mockResolvedValue(undefined) |
60 | | - const config = {static_root: 'public'} |
61 | | - const directory = '/app/root' |
62 | | - const outputPath = '/output/dist/bundle.js' |
63 | | - |
64 | | - await spec.copyStaticAssets!(config, directory, outputPath) |
65 | | - |
66 | | - expect(copyDirectoryContents).toHaveBeenCalledWith('/app/root/public', '/output/dist') |
| 54 | + describe('buildConfig', () => { |
| 55 | + test('should use copy_files mode', () => { |
| 56 | + expect(spec.buildConfig.mode).toBe('copy_files') |
67 | 57 | }) |
68 | 58 |
|
69 | | - test('should not copy assets when static_root is not provided', async () => { |
70 | | - const config = {} |
71 | | - const directory = '/app/root' |
72 | | - const outputPath = '/output/dist/bundle.js' |
73 | | - |
74 | | - await spec.copyStaticAssets!(config, directory, outputPath) |
| 59 | + test('should have copy-static-assets step with tomlKey entry', () => { |
| 60 | + if (spec.buildConfig.mode === 'none') { |
| 61 | + throw new Error('Expected build_steps mode') |
| 62 | + } |
75 | 63 |
|
76 | | - expect(copyDirectoryContents).not.toHaveBeenCalled() |
| 64 | + expect(spec.buildConfig.steps).toHaveLength(1) |
| 65 | + expect(spec.buildConfig.steps![0]).toMatchObject({ |
| 66 | + id: 'copy-static-assets', |
| 67 | + displayName: 'Copy Static Assets', |
| 68 | + type: 'copy_files', |
| 69 | + config: { |
| 70 | + strategy: 'files', |
| 71 | + definition: {files: [{tomlKey: 'static_root'}]}, |
| 72 | + }, |
| 73 | + }) |
| 74 | + expect(spec.buildConfig.stopOnError).toBe(true) |
77 | 75 | }) |
78 | 76 |
|
79 | | - test('should throw error when copy fails', async () => { |
80 | | - vi.mocked(copyDirectoryContents).mockRejectedValue(new Error('Permission denied')) |
81 | | - const config = {static_root: 'public'} |
82 | | - const directory = '/app/root' |
83 | | - const outputPath = '/output/dist/bundle.js' |
| 77 | + test('config should be serializable to JSON', () => { |
| 78 | + if (spec.buildConfig.mode === 'none') { |
| 79 | + throw new Error('Expected build_steps mode') |
| 80 | + } |
84 | 81 |
|
85 | | - await expect(spec.copyStaticAssets!(config, directory, outputPath)).rejects.toThrow( |
86 | | - 'Failed to copy static assets from /app/root/public to /output/dist: Permission denied', |
87 | | - ) |
88 | | - }) |
89 | | - }) |
| 82 | + const serialized = JSON.stringify(spec.buildConfig) |
| 83 | + expect(serialized).toBeDefined() |
90 | 84 |
|
91 | | - describe('buildConfig', () => { |
92 | | - test('should have hosted_app_home build mode', () => { |
93 | | - expect(spec.buildConfig).toEqual({mode: 'hosted_app_home'}) |
| 85 | + const deserialized = JSON.parse(serialized) |
| 86 | + expect(deserialized.steps).toHaveLength(1) |
| 87 | + expect(deserialized.steps[0].config).toEqual({ |
| 88 | + strategy: 'files', |
| 89 | + definition: {files: [{tomlKey: 'static_root'}]}, |
| 90 | + }) |
94 | 91 | }) |
95 | 92 | }) |
96 | 93 |
|
|
0 commit comments