|
| 1 | +import { expandProjectConfig } from '../playground-project.js'; |
| 2 | +import { assert } from '@esm-bundle/chai'; |
| 3 | + |
| 4 | +// Removed MockResponse interface as it's not needed. |
| 5 | + |
| 6 | +suite('expandProjectConfig cdnBaseUrl behavior', () => { |
| 7 | + const originalFetch = globalThis.fetch; |
| 8 | + |
| 9 | + setup(() => { |
| 10 | + // Mock fetch to return a parent config when requested |
| 11 | + globalThis.fetch = async (input: RequestInfo | URL): Promise<Response> => { |
| 12 | + const url = typeof input === 'string' ? input : input.toString(); |
| 13 | + if (url.endsWith('parent-config.json')) { |
| 14 | + return { |
| 15 | + status: 200, |
| 16 | + json: async () => ({ |
| 17 | + files: { |
| 18 | + 'parent.txt': { content: 'parent content' } |
| 19 | + }, |
| 20 | + cdnBaseUrl: 'https://parent-cdn.com' |
| 21 | + }), |
| 22 | + text: async () => 'parent config' |
| 23 | + } as Response; |
| 24 | + } |
| 25 | + return { |
| 26 | + status: 404, |
| 27 | + json: async () => ({}), |
| 28 | + text: async () => 'Not Found' |
| 29 | + } as Response; |
| 30 | + }; |
| 31 | + }); |
| 32 | + |
| 33 | + teardown(() => { |
| 34 | + // Restore original fetch |
| 35 | + globalThis.fetch = originalFetch; |
| 36 | + }); |
| 37 | + |
| 38 | + test("should use parent's cdnBaseUrl when child does not define one", async () => { |
| 39 | + const childConfig = { |
| 40 | + files: { |
| 41 | + 'child.txt': { content: 'child content' } |
| 42 | + }, |
| 43 | + extends: 'https://example.com/parent-config.json' |
| 44 | + }; |
| 45 | + |
| 46 | + const result = await expandProjectConfig(childConfig, 'https://example.com/'); |
| 47 | + assert.equal(result.cdnBaseUrl, 'https://parent-cdn.com'); |
| 48 | + }); |
| 49 | + |
| 50 | + test("should prefer child's cdnBaseUrl over parent's when defined", async () => { |
| 51 | + const childConfig = { |
| 52 | + files: { |
| 53 | + 'child.txt': { content: 'child content' } |
| 54 | + }, |
| 55 | + cdnBaseUrl: 'https://child-cdn.com', |
| 56 | + extends: 'https://example.com/parent-config.json' |
| 57 | + }; |
| 58 | + |
| 59 | + const result = await expandProjectConfig(childConfig, 'https://example.com/'); |
| 60 | + assert.equal(result.cdnBaseUrl, 'https://child-cdn.com'); |
| 61 | + }); |
| 62 | +}); |
0 commit comments