Skip to content

Commit c8d8e33

Browse files
committed
Fix loader error for local mode
1 parent 0480194 commit c8d8e33

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

packages/app/src/cli/models/app/loader.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,66 @@ wrong = "property"
479479
expect(app.errors).toBeUndefined()
480480
})
481481

482+
test('throws error for duplicated handles when mode is local', async () => {
483+
// Given
484+
await writeConfig(appConfiguration)
485+
486+
const blockConfiguration = `
487+
api_version = "2022-07"
488+
489+
[[extensions]]
490+
type = "checkout_post_purchase"
491+
name = "my_extension_1"
492+
handle = "handle-1"
493+
description = "custom description"
494+
495+
[[extensions]]
496+
type = "flow_action"
497+
handle = "handle-1"
498+
name = "my_extension_1_flow"
499+
description = "custom description"
500+
runtime_url = "https://example.com"
501+
`
502+
await writeBlockConfig({
503+
blockConfiguration,
504+
name: 'my_extension_1',
505+
})
506+
await writeFile(joinPath(blockPath('my_extension_1'), 'index.js'), '')
507+
508+
// When/Then
509+
await expect(loadTestingApp({mode: 'local'})).rejects.toThrow(/Duplicated handle/)
510+
})
511+
512+
test('does not throw error for duplicated handles when mode is report', async () => {
513+
// Given
514+
await writeConfig(appConfiguration)
515+
516+
const blockConfiguration = `
517+
api_version = "2022-07"
518+
519+
[[extensions]]
520+
type = "checkout_post_purchase"
521+
name = "my_extension_1"
522+
handle = "handle-1"
523+
description = "custom description"
524+
525+
[[extensions]]
526+
type = "flow_action"
527+
handle = "handle-1"
528+
name = "my_extension_1_flow"
529+
description = "custom description"
530+
runtime_url = "https://example.com"
531+
`
532+
await writeBlockConfig({
533+
blockConfiguration,
534+
name: 'my_extension_1',
535+
})
536+
await writeFile(joinPath(blockPath('my_extension_1'), 'index.js'), '')
537+
538+
// When/Then
539+
await expect(loadTestingApp({mode: 'report'})).resolves.not.toThrow()
540+
})
541+
482542
test('throws if 2 or more extensions have the same handle', async () => {
483543
// Given
484544
await writeConfig(appConfiguration)

packages/app/src/cli/models/app/loader.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,13 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
737737
}
738738

739739
private abortOrReport<T>(errorMessage: OutputMessage, fallback: T, configurationPath: string): T {
740-
if (this.mode === 'strict') {
741-
throw new AbortError(errorMessage)
742-
} else {
743-
this.errors.addError(configurationPath, errorMessage)
744-
return fallback
740+
switch (this.mode) {
741+
case 'strict':
742+
case 'local':
743+
throw new AbortError(errorMessage)
744+
case 'report':
745+
this.errors.addError(configurationPath, errorMessage)
746+
return fallback
745747
}
746748
}
747749

0 commit comments

Comments
 (0)