fix(tests): update WasmProvider tests to handle unversioned CDN URLs from older releases

This commit is contained in:
alam00000
2026-10-28 12:27:28 +05:30
parent d8210be3c1
commit 27dfe79636
2 changed files with 20 additions and 2 deletions
+5 -2
View File
@@ -59,8 +59,11 @@ const BUILTIN_TRUSTED_HOSTS = collectBuiltinTrustedHosts();
function isOutdatedCdnPin(packageName: WasmPackage, url: string): boolean {
const current = CDN_DEFAULTS[packageName];
const packagePrefix = current.slice(0, current.lastIndexOf('@') + 1);
return url !== current && url.startsWith(packagePrefix);
const packageUrl = current.slice(0, current.lastIndexOf('@'));
return (
url !== current &&
(url.startsWith(`${packageUrl}@`) || url.startsWith(`${packageUrl}/`))
);
}
function withTrailingSlash(url: string): string {
+15
View File
@@ -39,6 +39,21 @@ describe('WasmProvider saved URLs', () => {
expect(storedConfig()).toEqual({});
});
it('replaces an unversioned CDN URL saved by older releases', async () => {
const provider = await loadProvider({
ghostscript: 'https://cdn.jsdelivr.net/npm/@bentopdf/gs-wasm/assets/',
cpdf: 'https://cdn.jsdelivr.net/npm/coherentpdf/dist/',
});
expect(provider.getUrl('ghostscript')).toBe(
'https://cdn.jsdelivr.net/npm/@bentopdf/gs-wasm@0.1.1/assets/'
);
expect(provider.getUrl('cpdf')).toBe(
'https://cdn.jsdelivr.net/npm/coherentpdf@2.5.5/dist/'
);
expect(storedConfig()).toEqual({});
});
it('keeps a self-hosted URL the user chose', async () => {
const provider = await loadProvider({
pymupdf: 'http://localhost/wasm/pymupdf/',