Skip to content

Commit cd0aa97

Browse files
e111077Elliott Marquez
authored andcommitted
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 cd0aa97

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/playground-project.ts

Lines changed: 2 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,5 @@ const playgroundFilesDeepEqual = (
10901089
}
10911090
return true;
10921091
};
1092+
1093+
export { fetchProjectConfig, expandProjectConfig };

src/test/expanded-config_test.ts

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

0 commit comments

Comments
 (0)