@@ -14,7 +14,9 @@ import chokidar from 'chokidar'
1414import { deleteThemeAssets , fetchThemeAssets } from '@shopify/cli-kit/node/themes/api'
1515import { renderError } from '@shopify/cli-kit/node/ui'
1616import { Operation , type Checksum , type ThemeAsset } from '@shopify/cli-kit/node/themes/types'
17+ import { dirname , joinPath } from '@shopify/cli-kit/node/path'
1718import EventEmitter from 'events'
19+ import { fileURLToPath } from 'node:url'
1820
1921vi . mock ( '@shopify/cli-kit/node/fs' , async ( realImport ) => {
2022 const realModule = await realImport < typeof import ( '@shopify/cli-kit/node/fs' ) > ( )
@@ -34,10 +36,12 @@ beforeEach(async () => {
3436} )
3537
3638describe ( 'theme-fs' , ( ) => {
39+ const locationOfThisFile = dirname ( fileURLToPath ( import . meta. url ) )
40+
3741 describe ( 'mountThemeFileSystem' , async ( ) => {
3842 test ( 'mounts the local theme file system when the directory is valid' , async ( ) => {
3943 // Given
40- const root = 'src/cli/utilities/ fixtures/theme'
44+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
4145
4246 // When
4347 const themeFileSystem = mountThemeFileSystem ( root )
@@ -72,7 +76,7 @@ describe('theme-fs', () => {
7276
7377 test ( 'mounts an empty file system when the directory is invalid' , async ( ) => {
7478 // Given
75- const root = 'src/cli/utilities/ invalid-directory'
79+ const root = joinPath ( locationOfThisFile , ' invalid-directory')
7680
7781 // When
7882 const themeFileSystem = mountThemeFileSystem ( root )
@@ -96,7 +100,7 @@ describe('theme-fs', () => {
96100
97101 test ( '"delete" removes the file from the local disk and updates the file map' , async ( ) => {
98102 // Given
99- const root = 'src/cli/utilities/ fixtures/theme'
103+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
100104
101105 // When
102106 const themeFileSystem = mountThemeFileSystem ( root )
@@ -112,7 +116,7 @@ describe('theme-fs', () => {
112116 describe ( 'themeFileSystem.delete' , ( ) => {
113117 test ( '"delete" removes the file from the local disk and updates the file map' , async ( ) => {
114118 // Given
115- const root = 'src/cli/utilities/ fixtures/theme'
119+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
116120
117121 // When
118122 const themeFileSystem = mountThemeFileSystem ( root )
@@ -127,7 +131,7 @@ describe('theme-fs', () => {
127131
128132 test ( 'does nothing when the theme file does not exist on local disk' , async ( ) => {
129133 // Given
130- const root = 'src/cli/utilities/ fixtures/theme'
134+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
131135
132136 // When
133137 const themeFileSystem = mountThemeFileSystem ( root )
@@ -142,7 +146,7 @@ describe('theme-fs', () => {
142146 test ( 'delete updates files map before the async removeFile call' , async ( ) => {
143147 // Given
144148 const fileKey = 'assets/base.css'
145- const root = 'src/cli/utilities/ fixtures/theme'
149+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
146150 const themeFileSystem = mountThemeFileSystem ( root )
147151 await themeFileSystem . ready ( )
148152
@@ -164,7 +168,7 @@ describe('theme-fs', () => {
164168 describe ( 'themeFileSystem.write' , ( ) => {
165169 test ( '"write" creates a file on the local disk and updates the file map' , async ( ) => {
166170 // Given
167- const root = 'src/cli/utilities/ fixtures/theme'
171+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
168172
169173 // When
170174 const themeFileSystem = mountThemeFileSystem ( root )
@@ -186,7 +190,7 @@ describe('theme-fs', () => {
186190
187191 test ( '"write" creates an image file on the local disk and updates the file map' , async ( ) => {
188192 // Given
189- const root = 'src/cli/utilities/ fixtures/theme'
193+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
190194 const attachment = '0x123!'
191195 const buffer = Buffer . from ( attachment , 'base64' )
192196
@@ -210,7 +214,7 @@ describe('theme-fs', () => {
210214
211215 test ( 'write updates files map before the async writeFile call' , async ( ) => {
212216 // Given
213- const root = 'src/cli/utilities/ fixtures'
217+ const root = joinPath ( locationOfThisFile , ' fixtures')
214218 const themeFileSystem = mountThemeFileSystem ( root )
215219 await themeFileSystem . ready ( )
216220
@@ -240,7 +244,7 @@ describe('theme-fs', () => {
240244 describe ( 'themeFileSystem.read' , async ( ) => {
241245 test ( '"read" returns the content from the local disk and updates the file map' , async ( ) => {
242246 // Given
243- const root = 'src/cli/utilities/ fixtures/theme'
247+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
244248 const key = 'templates/404.json'
245249 const themeFileSystem = mountThemeFileSystem ( root )
246250 await themeFileSystem . ready ( )
@@ -270,7 +274,7 @@ describe('theme-fs', () => {
270274
271275 describe ( 'themeFileSystem.applyIgnoreFilters' , async ( ) => {
272276 test ( 'applies ignore filters to the theme files' , async ( ) => {
273- const root = 'src/cli/utilities/ fixtures'
277+ const root = joinPath ( locationOfThisFile , ' fixtures')
274278 const files = [ { key : 'assets/file.css' } , { key : 'assets/file.json' } ]
275279 const options = { filters : { ignore : [ 'assets/*.css' ] } }
276280
@@ -290,7 +294,7 @@ describe('theme-fs', () => {
290294 describe ( 'readThemeFile' , ( ) => {
291295 test ( 'reads theme file when it exists' , async ( ) => {
292296 // Given
293- const root = 'src/cli/utilities/ fixtures/theme'
297+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
294298 const key = 'templates/404.json'
295299
296300 // When
@@ -312,7 +316,7 @@ describe('theme-fs', () => {
312316
313317 test ( `returns undefined when theme file doesn't exist` , async ( ) => {
314318 // Given
315- const root = 'src/cli/utilities/ fixtures/theme'
319+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
316320 const key = 'templates/invalid.json'
317321
318322 // When
@@ -324,7 +328,7 @@ describe('theme-fs', () => {
324328
325329 test ( 'returns Buffer for image files' , async ( ) => {
326330 // Given
327- const root = 'src/cli/utilities/ fixtures/theme'
331+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
328332 const key = 'assets/sparkle.gif'
329333
330334 // When
@@ -477,7 +481,7 @@ describe('theme-fs', () => {
477481 describe ( 'hasRequiredThemeDirectories' , ( ) => {
478482 test ( `returns true when directory has all required theme directories` , async ( ) => {
479483 // Given
480- const root = 'src/cli/utilities/ fixtures/theme'
484+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
481485
482486 // When
483487 const result = await hasRequiredThemeDirectories ( root )
@@ -488,7 +492,7 @@ describe('theme-fs', () => {
488492
489493 test ( `returns false when directory doesn't have all required theme directories` , async ( ) => {
490494 // Given
491- const root = 'src/cli/utilities'
495+ const root = locationOfThisFile
492496
493497 // When
494498 const result = await hasRequiredThemeDirectories ( root )
@@ -501,7 +505,7 @@ describe('theme-fs', () => {
501505 describe ( 'handleFileDelete' , ( ) => {
502506 const themeId = '1'
503507 const adminSession = { token : 'token' , storeFqdn : 'store.myshopify.com' }
504- const root = 'src/cli/utilities/ fixtures/theme'
508+ const root = joinPath ( locationOfThisFile , ' fixtures/theme')
505509
506510 beforeEach ( ( ) => {
507511 const mockWatcher = new EventEmitter ( )
0 commit comments