From cd0aa97ae9e70812eac0b49fc083d1272174e3c9 Mon Sep 17 00:00:00 2001 From: Elliott Marquez <5981958+e111077@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:28:57 -0700 Subject: [PATCH] fix(cdn): use the expanded cdn value rather than the last one fixes an issue where cdnBaseUrl is not inheriting from parent project.jsons because it's using the top level config and not the expanded one --- src/playground-project.ts | 3 +- src/test/expanded-config_test.ts | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/expanded-config_test.ts diff --git a/src/playground-project.ts b/src/playground-project.ts index 906c86f3..901e6ce2 100644 --- a/src/playground-project.ts +++ b/src/playground-project.ts @@ -833,7 +833,6 @@ const fetchProjectConfig = async ( return { ...result, - cdnBaseUrl: config.cdnBaseUrl, }; }; @@ -1090,3 +1089,5 @@ const playgroundFilesDeepEqual = ( } return true; }; + +export { fetchProjectConfig, expandProjectConfig }; diff --git a/src/test/expanded-config_test.ts b/src/test/expanded-config_test.ts new file mode 100644 index 00000000..9446f9e9 --- /dev/null +++ b/src/test/expanded-config_test.ts @@ -0,0 +1,60 @@ +import { expandProjectConfig } from '../playground-project.js'; +import { assert } from '@esm-bundle/chai'; + +suite('expandProjectConfig cdnBaseUrl behavior', () => { + const originalFetch = globalThis.fetch; + + setup(() => { + // Mock fetch to return a parent config when requested + globalThis.fetch = async (input: RequestInfo | URL): Promise => { + const url = typeof input === 'string' ? input : input.toString(); + if (url.endsWith('parent-config.json')) { + return { + status: 200, + json: async () => ({ + files: { + 'parent.txt': { content: 'parent content' } + }, + cdnBaseUrl: 'https://parent-cdn.com' + }), + text: async () => 'parent config' + } as Response; + } + return { + status: 404, + json: async () => ({}), + text: async () => 'Not Found' + } as Response; + }; + }); + + teardown(() => { + // Restore original fetch + globalThis.fetch = originalFetch; + }); + + test("should use parent's cdnBaseUrl when child does not define one", async () => { + const childConfig = { + files: { + 'child.txt': { content: 'child content' } + }, + extends: 'https://example.com/parent-config.json' + }; + + const result = await expandProjectConfig(childConfig, 'https://example.com/'); + assert.equal(result.cdnBaseUrl, 'https://parent-cdn.com'); + }); + + test("should prefer child's cdnBaseUrl over parent's when defined", async () => { + const childConfig = { + files: { + 'child.txt': { content: 'child content' } + }, + cdnBaseUrl: 'https://child-cdn.com', + extends: 'https://example.com/parent-config.json' + }; + + const result = await expandProjectConfig(childConfig, 'https://example.com/'); + assert.equal(result.cdnBaseUrl, 'https://child-cdn.com'); + }); +});