Skip to content

Commit 66b9c54

Browse files
committed
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
1 parent a300acb commit 66b9c54

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/playground-project.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,6 @@ const fetchProjectConfig = async (
833833

834834
return {
835835
...result,
836-
cdnBaseUrl: config.cdnBaseUrl,
837836
};
838837
};
839838

@@ -1090,3 +1089,6 @@ const playgroundFilesDeepEqual = (
10901089
}
10911090
return true;
10921091
};
1092+
1093+
// Export functions for testing
1094+
export { fetchProjectConfig, expandProjectConfig };

src/test/expanded-config_test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)