mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 00:28:39 +01:00
fix(tests): update WasmProvider tests to handle unversioned CDN URLs from older releases
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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/',
|
||||
|
||||
Reference in New Issue
Block a user