|
1 | | -import {resolveDotEnv, resolveHiddenConfig, extensionFilesForConfig, webFilesForConfig} from './config-selection.js' |
| 1 | +import { |
| 2 | + resolveDotEnv, |
| 3 | + resolveHiddenConfig, |
| 4 | + extensionFilesForConfig, |
| 5 | + malformedExtensionFilesForConfig, |
| 6 | + malformedWebFilesForConfig, |
| 7 | + webFilesForConfig, |
| 8 | +} from './config-selection.js' |
2 | 9 | import {Project} from './project.js' |
3 | 10 | import {describe, expect, test} from 'vitest' |
4 | 11 | import {inTemporaryDirectory, writeFile, mkdir} from '@shopify/cli-kit/node/fs' |
@@ -230,6 +237,33 @@ describe('extensionFilesForConfig', () => { |
230 | 237 | expect(stagingExts[0]!.content.name).toBe('func2') |
231 | 238 | }) |
232 | 239 | }) |
| 240 | + |
| 241 | + test('filters malformed extension files to the active config extension_directories', async () => { |
| 242 | + await inTemporaryDirectory(async (dir) => { |
| 243 | + await writeFile(joinPath(dir, 'shopify.app.toml'), 'client_id = "default"\nextension_directories = ["ext-a/*"]') |
| 244 | + await writeFile( |
| 245 | + joinPath(dir, 'shopify.app.staging.toml'), |
| 246 | + 'client_id = "staging"\nextension_directories = ["ext-b/*"]', |
| 247 | + ) |
| 248 | + |
| 249 | + await mkdir(joinPath(dir, 'ext-a', 'broken-default')) |
| 250 | + await writeFile(joinPath(dir, 'ext-a', 'broken-default', 'shopify.extension.toml'), '{{broken toml') |
| 251 | + await mkdir(joinPath(dir, 'ext-b', 'broken-staging')) |
| 252 | + await writeFile(joinPath(dir, 'ext-b', 'broken-staging', 'shopify.extension.toml'), '{{broken toml') |
| 253 | + |
| 254 | + const project = await Project.load(dir) |
| 255 | + const defaultConfig = project.appConfigByName('shopify.app.toml')! |
| 256 | + const stagingConfig = project.appConfigByName('shopify.app.staging.toml')! |
| 257 | + |
| 258 | + const defaultMalformed = malformedExtensionFilesForConfig(project, defaultConfig) |
| 259 | + expect(defaultMalformed).toHaveLength(1) |
| 260 | + expect(defaultMalformed[0]!.path).toContain('ext-a/broken-default/shopify.extension.toml') |
| 261 | + |
| 262 | + const stagingMalformed = malformedExtensionFilesForConfig(project, stagingConfig) |
| 263 | + expect(stagingMalformed).toHaveLength(1) |
| 264 | + expect(stagingMalformed[0]!.path).toContain('ext-b/broken-staging/shopify.extension.toml') |
| 265 | + }) |
| 266 | + }) |
233 | 267 | }) |
234 | 268 |
|
235 | 269 | describe('webFilesForConfig', () => { |
@@ -287,4 +321,28 @@ describe('webFilesForConfig', () => { |
287 | 321 | expect(webFiles[0]!.content.name).toBe('web-a') |
288 | 322 | }) |
289 | 323 | }) |
| 324 | + |
| 325 | + test('filters malformed web files to the active config web_directories', async () => { |
| 326 | + await inTemporaryDirectory(async (dir) => { |
| 327 | + await writeFile(joinPath(dir, 'shopify.app.toml'), 'client_id = "default"\nweb_directories = ["web-a"]') |
| 328 | + await writeFile(joinPath(dir, 'shopify.app.staging.toml'), 'client_id = "staging"\nweb_directories = ["web-b"]') |
| 329 | + |
| 330 | + await mkdir(joinPath(dir, 'web-a')) |
| 331 | + await writeFile(joinPath(dir, 'web-a', 'shopify.web.toml'), '{{broken toml') |
| 332 | + await mkdir(joinPath(dir, 'web-b')) |
| 333 | + await writeFile(joinPath(dir, 'web-b', 'shopify.web.toml'), '{{broken toml') |
| 334 | + |
| 335 | + const project = await Project.load(dir) |
| 336 | + const defaultConfig = project.appConfigByName('shopify.app.toml')! |
| 337 | + const stagingConfig = project.appConfigByName('shopify.app.staging.toml')! |
| 338 | + |
| 339 | + const defaultMalformed = malformedWebFilesForConfig(project, defaultConfig) |
| 340 | + expect(defaultMalformed).toHaveLength(1) |
| 341 | + expect(defaultMalformed[0]!.path).toContain('web-a/shopify.web.toml') |
| 342 | + |
| 343 | + const stagingMalformed = malformedWebFilesForConfig(project, stagingConfig) |
| 344 | + expect(stagingMalformed).toHaveLength(1) |
| 345 | + expect(stagingMalformed[0]!.path).toContain('web-b/shopify.web.toml') |
| 346 | + }) |
| 347 | + }) |
290 | 348 | }) |
0 commit comments