Skip to content

Commit 7db60d6

Browse files
authored
Merge pull request #5364 from Shopify/shauns/02-05-fix_cross-workspace_vitest
Fix cross-workspace vitest
2 parents eafa589 + 4b0695a commit 7db60d6

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@
3838
"testing.automaticallyOpenPeekView": "never",
3939
"javascript.preferences.importModuleSpecifierEnding": "js",
4040
"typescript.preferences.importModuleSpecifierEnding": "js",
41-
"vitest.nodeEnv": {"VITEST_SKIP_TIMEOUT": "1"}
41+
"vitest.nodeEnv": {
42+
"npm_config_user_agent": "pnpm",
43+
"VITEST_SKIP_TIMEOUT": "1"
44+
}
4245
}

packages/theme/src/cli/utilities/asset-checksum.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {calculateChecksum, rejectGeneratedStaticAssets} from './asset-checksum.js'
22
import {readThemeFile} from './theme-fs.js'
33
import {describe, expect, test} from 'vitest'
4+
import {joinPath, dirname} from '@shopify/cli-kit/node/path'
5+
import {fileURLToPath} from 'node:url'
46

57
describe('asset-checksum', () => {
8+
const locationOfThisFile = dirname(fileURLToPath(import.meta.url))
9+
610
describe('calculateChecksum', async () => {
711
const testCases = [
812
{file: 'assets/base.css', expectedChecksum: 'b7fbe0ecff2a6c1d6e697a13096e2b17'},
@@ -19,7 +23,7 @@ describe('asset-checksum', () => {
1923
testCases.forEach(({file, expectedChecksum}) => {
2024
test(`returns the expected checksum for "${file}"`, async () => {
2125
// Given
22-
const root = 'src/cli/utilities/fixtures/theme'
26+
const root = joinPath(locationOfThisFile, 'fixtures/theme')
2327
const content = await readThemeFile(root, file)
2428

2529
// When

packages/theme/src/cli/utilities/theme-ext-environment/theme-ext-fs.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import {mountThemeExtensionFileSystem} from './theme-ext-fs.js'
22
import {test, describe, expect} from 'vitest'
3+
import {dirname, joinPath} from '@shopify/cli-kit/node/path'
4+
import {fileURLToPath} from 'node:url'
35
import type {Checksum, ThemeAsset} from '@shopify/cli-kit/node/themes/types'
46

57
describe('theme-ext-fs', () => {
8+
const locationOfThisFile = dirname(fileURLToPath(import.meta.url))
9+
610
describe('mountThemeExtensionFileSystem', async () => {
711
test('mounts the local theme file system when the directory is valid', async () => {
812
// Given
9-
const root = 'src/cli/utilities/fixtures/theme-ext'
13+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
1014

1115
// When
1216
const themeFileSystem = mountThemeExtensionFileSystem(root)
@@ -33,7 +37,7 @@ describe('theme-ext-fs', () => {
3337

3438
test('mounts an empty file system when the directory is invalid', async () => {
3539
// Given
36-
const root = 'src/cli/utilities/invalid-directory'
40+
const root = joinPath(locationOfThisFile, 'invalid-directory')
3741

3842
// When
3943
const themeFileSystem = mountThemeExtensionFileSystem(root)
@@ -57,7 +61,7 @@ describe('theme-ext-fs', () => {
5761
describe('delete', () => {
5862
test('"delete" removes the file from the file map', async () => {
5963
// Given
60-
const root = 'src/cli/utilities/fixtures/theme-ext'
64+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
6165
const themeFileSystem = mountThemeExtensionFileSystem(root)
6266
await themeFileSystem.ready()
6367

@@ -71,7 +75,7 @@ describe('theme-ext-fs', () => {
7175

7276
test('does nothing when the theme file does not exist', async () => {
7377
// Given
74-
const root = 'src/cli/utilities/fixtures/theme-ext'
78+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
7579

7680
// When
7781
const themeFileSystem = mountThemeExtensionFileSystem(root)
@@ -86,7 +90,7 @@ describe('theme-ext-fs', () => {
8690
describe('write', () => {
8791
test('"write" creates a file on the file map', async () => {
8892
// Given
89-
const root = 'src/cli/utilities/fixtures/theme-ext'
93+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
9094
const themeFileSystem = mountThemeExtensionFileSystem(root)
9195
await themeFileSystem.ready()
9296

@@ -104,7 +108,7 @@ describe('theme-ext-fs', () => {
104108

105109
test('"write" creates an image file on the file map', async () => {
106110
// Given
107-
const root = 'src/cli/utilities/fixtures/theme-ext'
111+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
108112
const attachment = '0x123!'
109113
const themeFileSystem = mountThemeExtensionFileSystem(root)
110114
await themeFileSystem.ready()
@@ -126,7 +130,7 @@ describe('theme-ext-fs', () => {
126130
describe('read', async () => {
127131
test('"read" returns returns the content from the local disk and updates the file map', async () => {
128132
// Given
129-
const root = 'src/cli/utilities/fixtures/theme-ext'
133+
const root = joinPath(locationOfThisFile, '../fixtures/theme-ext')
130134
const key = 'snippets/stars.liquid'
131135
const themeFileSystem = mountThemeExtensionFileSystem(root)
132136
await themeFileSystem.ready()

packages/theme/src/cli/utilities/theme-fs.test.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import chokidar from 'chokidar'
1414
import {deleteThemeAssets, fetchThemeAssets} from '@shopify/cli-kit/node/themes/api'
1515
import {renderError} from '@shopify/cli-kit/node/ui'
1616
import {Operation, type Checksum, type ThemeAsset} from '@shopify/cli-kit/node/themes/types'
17+
import {dirname, joinPath} from '@shopify/cli-kit/node/path'
1718
import EventEmitter from 'events'
19+
import {fileURLToPath} from 'node:url'
1820

1921
vi.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

3638
describe('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

Comments
 (0)