@@ -3,9 +3,9 @@ import {inTemporaryDirectory, writeFile, fileExists, mkdir, readFile} from '@sho
33import { joinPath } from '@shopify/cli-kit/node/path'
44import { describe , expect , test , vi , beforeEach } from 'vitest'
55
6- const makeContext = ( configuration : Record < string , unknown > ) => ( {
6+ const makeContext = ( configuration : Record < string , unknown > , stdout : any = { write : vi . fn ( ) } ) => ( {
77 extension : { configuration} as any ,
8- options : { } as any ,
8+ options : { stdout } as any ,
99 stepResults : new Map ( ) ,
1010} )
1111
@@ -26,11 +26,8 @@ describe('copyConfigKeyEntry', () => {
2626 const outDir = joinPath ( tmpDir , 'out' )
2727 await mkdir ( outDir )
2828
29- const context = makeContext ( { static_root : 'public' } )
30- const result = await copyConfigKeyEntry (
31- { key : 'static_root' , baseDir : tmpDir , outputDir : outDir , context} ,
32- { stdout : mockStdout } ,
33- )
29+ const context = makeContext ( { static_root : 'public' } , mockStdout )
30+ const result = await copyConfigKeyEntry ( { key : 'static_root' , baseDir : tmpDir , outputDir : outDir , context} )
3431
3532 expect ( result . filesCopied ) . toBe ( 2 )
3633 await expect ( fileExists ( joinPath ( outDir , 'index.html' ) ) ) . resolves . toBe ( true )
@@ -49,11 +46,8 @@ describe('copyConfigKeyEntry', () => {
4946 const outDir = joinPath ( tmpDir , 'out' )
5047 await mkdir ( outDir )
5148
52- const context = makeContext ( { schema_path : 'src/schema.json' } )
53- const result = await copyConfigKeyEntry (
54- { key : 'schema_path' , baseDir : tmpDir , outputDir : outDir , context} ,
55- { stdout : mockStdout } ,
56- )
49+ const context = makeContext ( { schema_path : 'src/schema.json' } , mockStdout )
50+ const result = await copyConfigKeyEntry ( { key : 'schema_path' , baseDir : tmpDir , outputDir : outDir , context} )
5751
5852 expect ( result . filesCopied ) . toBe ( 1 )
5953 await expect ( fileExists ( joinPath ( outDir , 'schema.json' ) ) ) . resolves . toBe ( true )
@@ -74,11 +68,8 @@ describe('copyConfigKeyEntry', () => {
7468 // Pre-create the first candidate to force a rename
7569 await writeFile ( joinPath ( outDir , 'tools-a.json' ) , 'existing' )
7670
77- const context = makeContext ( { files : [ 'tools-a.json' , 'tools-b.json' ] } )
78- const result = await copyConfigKeyEntry (
79- { key : 'files' , baseDir : tmpDir , outputDir : outDir , context} ,
80- { stdout : mockStdout } ,
81- )
71+ const context = makeContext ( { files : [ 'tools-a.json' , 'tools-b.json' ] } , mockStdout )
72+ const result = await copyConfigKeyEntry ( { key : 'files' , baseDir : tmpDir , outputDir : outDir , context} )
8273
8374 expect ( result . filesCopied ) . toBe ( 2 )
8475 // tools-a.json was taken, so the copy lands as tools-a-1.json
@@ -92,11 +83,8 @@ describe('copyConfigKeyEntry', () => {
9283 const outDir = joinPath ( tmpDir , 'out' )
9384 await mkdir ( outDir )
9485
95- const context = makeContext ( { } )
96- const result = await copyConfigKeyEntry (
97- { key : 'static_root' , baseDir : tmpDir , outputDir : outDir , context} ,
98- { stdout : mockStdout } ,
99- )
86+ const context = makeContext ( { } , mockStdout )
87+ const result = await copyConfigKeyEntry ( { key : 'static_root' , baseDir : tmpDir , outputDir : outDir , context} )
10088
10189 expect ( result . filesCopied ) . toBe ( 0 )
10290 expect ( result . pathMap . size ) . toBe ( 0 )
@@ -109,11 +97,8 @@ describe('copyConfigKeyEntry', () => {
10997 await mkdir ( outDir )
11098
11199 // 'nonexistent' directory is NOT created, so fileExists returns false naturally
112- const context = makeContext ( { assets_dir : 'nonexistent' } )
113- const result = await copyConfigKeyEntry (
114- { key : 'assets_dir' , baseDir : tmpDir , outputDir : outDir , context} ,
115- { stdout : mockStdout } ,
116- )
100+ const context = makeContext ( { assets_dir : 'nonexistent' } , mockStdout )
101+ const result = await copyConfigKeyEntry ( { key : 'assets_dir' , baseDir : tmpDir , outputDir : outDir , context} )
117102
118103 expect ( result . filesCopied ) . toBe ( 0 )
119104 expect ( result . pathMap . size ) . toBe ( 0 )
@@ -137,11 +122,8 @@ describe('copyConfigKeyEntry', () => {
137122 const outDir = joinPath ( tmpDir , 'out' )
138123 await mkdir ( outDir )
139124
140- const context = makeContext ( { roots : [ 'public' , 'assets' ] } )
141- const result = await copyConfigKeyEntry (
142- { key : 'roots' , baseDir : tmpDir , outputDir : outDir , context} ,
143- { stdout : mockStdout } ,
144- )
125+ const context = makeContext ( { roots : [ 'public' , 'assets' ] } , mockStdout )
126+ const result = await copyConfigKeyEntry ( { key : 'roots' , baseDir : tmpDir , outputDir : outDir , context} )
145127
146128 // Promise.all runs copies sequentially; glob on the shared outDir may see files
147129 // from the other copy, so the total count is at least 3 (one per real file).
@@ -161,11 +143,14 @@ describe('copyConfigKeyEntry', () => {
161143 const outDir = joinPath ( tmpDir , 'out' )
162144 await mkdir ( outDir )
163145
164- const context = makeContext ( { icons_dir : 'icons' } )
165- await copyConfigKeyEntry (
166- { key : 'icons_dir' , baseDir : tmpDir , outputDir : outDir , context, destination : 'static/icons' } ,
167- { stdout : mockStdout } ,
168- )
146+ const context = makeContext ( { icons_dir : 'icons' } , mockStdout )
147+ await copyConfigKeyEntry ( {
148+ key : 'icons_dir' ,
149+ baseDir : tmpDir ,
150+ outputDir : outDir ,
151+ context,
152+ destination : 'static/icons' ,
153+ } )
169154
170155 await expect ( fileExists ( joinPath ( outDir , 'static' , 'icons' , 'icon.svg' ) ) ) . resolves . toBe ( true )
171156 } )
@@ -186,10 +171,12 @@ describe('copyConfigKeyEntry', () => {
186171 { targeting : [ { schema : 'schema-c.json' } ] } ,
187172 ] ,
188173 } )
189- const result = await copyConfigKeyEntry (
190- { key : 'extensions[].targeting[].schema' , baseDir : tmpDir , outputDir : outDir , context} ,
191- { stdout : mockStdout } ,
192- )
174+ const result = await copyConfigKeyEntry ( {
175+ key : 'extensions[].targeting[].schema' ,
176+ baseDir : tmpDir ,
177+ outputDir : outDir ,
178+ context,
179+ } )
193180
194181 expect ( result . filesCopied ) . toBe ( 3 )
195182 await expect ( fileExists ( joinPath ( outDir , 'schema-a.json' ) ) ) . resolves . toBe ( true )
@@ -203,15 +190,20 @@ describe('copyConfigKeyEntry', () => {
203190 const outDir = joinPath ( tmpDir , 'out' )
204191 await mkdir ( outDir )
205192
206- const context = makeContext ( {
207- extensions : { targeting : { schema : 'schema.json' } } ,
208- } )
209-
210- const result = await copyConfigKeyEntry (
211- { key : 'extensions[].targeting[].schema' , baseDir : tmpDir , outputDir : outDir , context} ,
212- { stdout : mockStdout } ,
193+ const context = makeContext (
194+ {
195+ extensions : { targeting : { schema : 'schema.json' } } ,
196+ } ,
197+ mockStdout ,
213198 )
214199
200+ const result = await copyConfigKeyEntry ( {
201+ key : 'extensions[].targeting[].schema' ,
202+ baseDir : tmpDir ,
203+ outputDir : outDir ,
204+ context,
205+ } )
206+
215207 expect ( result . filesCopied ) . toBe ( 0 )
216208 expect ( result . pathMap . size ) . toBe ( 0 )
217209 } )
@@ -228,10 +220,12 @@ describe('copyConfigKeyEntry', () => {
228220 const context = makeContext ( {
229221 extensions : [ { targeting : [ { tools : 'tools.json' } , { tools : 'tools.json' } ] } ] ,
230222 } )
231- const result = await copyConfigKeyEntry (
232- { key : 'extensions[].targeting[].tools' , baseDir : tmpDir , outputDir : outDir , context} ,
233- { stdout : mockStdout } ,
234- )
223+ const result = await copyConfigKeyEntry ( {
224+ key : 'extensions[].targeting[].tools' ,
225+ baseDir : tmpDir ,
226+ outputDir : outDir ,
227+ context,
228+ } )
235229
236230 expect ( result . filesCopied ) . toBe ( 1 )
237231 await expect ( fileExists ( joinPath ( outDir , 'tools.json' ) ) ) . resolves . toBe ( true )
0 commit comments