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'); + }); +});