Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/playground-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ const fetchProjectConfig = async (

return {
...result,
cdnBaseUrl: config.cdnBaseUrl,
};
};

Expand Down Expand Up @@ -1090,3 +1089,5 @@ const playgroundFilesDeepEqual = (
}
return true;
};

export { fetchProjectConfig, expandProjectConfig };
60 changes: 60 additions & 0 deletions src/test/expanded-config_test.ts
Original file line number Diff line number Diff line change
@@ -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<Response> => {
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');
});
});