Changeset bdb78e4 in Klonkt for test/embed-resolver.test.js
- Timestamp:
- 07/28/2026 08:59:00 AM (6 weeks ago)
- Branches:
- main
- Children:
- 2a76184
- Parents:
- b1512e0
- File:
-
- 1 edited
-
test/embed-resolver.test.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
test/embed-resolver.test.js
rb1512e0 rbdb78e4 198 198 assert.equal(findOpenGraph(got).image, 'https://x/real.png', 'reads past the decoy to the real tag'); 199 199 }); 200 201 // The public oEmbed registry (oembed.com). Not a list we maintain: we read one 202 // that is published. It exists because discovery through the page fails exactly 203 // where it matters most, from a server YouTube hands a stripped page to. 204 const PROVIDERS = [ 205 { provider_name: 'YouTube', provider_url: 'https://www.youtube.com/', 206 endpoints: [{ schemes: ['https://*.youtube.com/watch*', 'https://youtu.be/*'], url: 'https://www.youtube.com/oembed' }] }, 207 { provider_name: 'Bare', provider_url: 'https://bare.example/', endpoints: [{ url: 'https://bare.example/oembed.{format}' }] }, 208 ]; 209 210 test('matchProviderEndpoint matches wildcard schemes and falls back to the host', async () => { 211 const { matchProviderEndpoint } = await import('../src/services/EmbedResolver.js'); 212 assert.equal(matchProviderEndpoint('https://youtu.be/abc?is=x', PROVIDERS), 'https://www.youtube.com/oembed'); 213 assert.equal(matchProviderEndpoint('https://www.youtube.com/watch?v=abc', PROVIDERS), 'https://www.youtube.com/oembed'); 214 assert.equal(matchProviderEndpoint('https://bare.example/thing/1', PROVIDERS), 'https://bare.example/oembed.json', 215 'no schemes listed, so the provider host decides, and {format} is filled in'); 216 assert.equal(matchProviderEndpoint('https://elders.example/x', PROVIDERS), null); 217 assert.equal(matchProviderEndpoint('not a url', PROVIDERS), null); 218 }); 219 220 test('oembedRequestUrl appends url + format, keeping an existing query', async () => { 221 const { oembedRequestUrl } = await import('../src/services/EmbedResolver.js'); 222 assert.ok(oembedRequestUrl('https://x/oembed', 'https://a/b?c=1').includes('format=json&url=https%3A%2F%2Fa%2Fb%3Fc%3D1')); 223 assert.ok(oembedRequestUrl('https://x/oembed?k=1', 'https://a/b').startsWith('https://x/oembed?k=1&')); 224 }); 225 226 test('the registry is tried before the page, and the page is not fetched when it hits', async () => { 227 let pageFetched = false; 228 const r = await resolveEmbed('https://youtu.be/abc', io({ 229 registry: async () => PROVIDERS, 230 getJSON: async () => OEMBED_JSON, 231 getPage: async () => { pageFetched = true; return OG_PAGE; }, 232 })); 233 assert.equal(r.kind, 'oembed'); 234 assert.equal(r.title, 'A talk'); 235 assert.ok(!pageFetched, 'a registry hit saves the whole page download'); 236 }); 237 238 test('an unreachable registry just falls through to the page', async () => { 239 const r = await resolveEmbed('https://lg.example/a', io({ 240 registry: async () => { throw new Error('offline'); }, 241 getPage: async () => OG_PAGE, 242 })); 243 assert.equal(r.kind, 'opengraph'); 244 });
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)