|
| 1 | +import{describe,expect,it}from'vitest' |
| 2 | +import{getBundleResolve,registry}from'../../packages/script/src/registry' |
| 3 | + |
| 4 | +asyncfunctiongetPlausibleResolve(){ |
| 5 | +constall=awaitregistry() |
| 6 | +constscript=all.find(s=>s.registryKey==='plausibleAnalytics')! |
| 7 | +constresolve=getBundleResolve(script) |
| 8 | +if(!resolve) |
| 9 | +thrownewError('plausibleAnalytics bundle.resolve missing') |
| 10 | +returnresolve |
| 11 | +} |
| 12 | + |
| 13 | +describe('plausibleAnalytics bundle.resolve',()=>{ |
| 14 | +it('returns default plausible.io URL with scriptId',async()=>{ |
| 15 | +constresolve=awaitgetPlausibleResolve() |
| 16 | +expect(resolve({scriptId: 'abc123'}asany)).toBe('https://plausible.io/js/pa-abc123.js') |
| 17 | +}) |
| 18 | + |
| 19 | +it('returns default plausible.io URL with legacy extension',async()=>{ |
| 20 | +constresolve=awaitgetPlausibleResolve() |
| 21 | +expect(resolve({extension: 'hash'}asany)).toBe('https://plausible.io/js/script.hash.js') |
| 22 | +}) |
| 23 | + |
| 24 | +it('returns default basic plausible.io URL with no options',async()=>{ |
| 25 | +constresolve=awaitgetPlausibleResolve() |
| 26 | +expect(resolve(undefined)).toBe('https://plausible.io/js/script.js') |
| 27 | +}) |
| 28 | + |
| 29 | +it('honors user-supplied scriptInput.src for self-hosted Plausible',async()=>{ |
| 30 | +// Regression test for https://github.com/nuxt/scripts/issues/768 |
| 31 | +constresolve=awaitgetPlausibleResolve() |
| 32 | +constselfHosted='https://my-self-hosted-plausible.io/js/script.js' |
| 33 | +expect( |
| 34 | +resolve({scriptId: 'abc123',scriptInput: {src: selfHosted}}asany), |
| 35 | +).toBe(selfHosted) |
| 36 | +expect( |
| 37 | +resolve({scriptInput: {src: selfHosted}}asany), |
| 38 | +).toBe(selfHosted) |
| 39 | +}) |
| 40 | +}) |
0 commit comments