|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { getBundleResolve, registry } from '../../packages/script/src/registry' |
| 3 | + |
| 4 | +async function getPlausibleResolve() { |
| 5 | + const all = await registry() |
| 6 | + const script = all.find(s => s.registryKey === 'plausibleAnalytics')! |
| 7 | + const resolve = getBundleResolve(script) |
| 8 | + if (!resolve) |
| 9 | + throw new Error('plausibleAnalytics bundle.resolve missing') |
| 10 | + return resolve |
| 11 | +} |
| 12 | + |
| 13 | +describe('plausibleAnalytics bundle.resolve', () => { |
| 14 | + it('returns default plausible.io URL with scriptId', async () => { |
| 15 | + const resolve = await getPlausibleResolve() |
| 16 | + expect(resolve({ scriptId: 'abc123' } as any)).toBe('https://plausible.io/js/pa-abc123.js') |
| 17 | + }) |
| 18 | + |
| 19 | + it('returns default plausible.io URL with legacy extension', async () => { |
| 20 | + const resolve = await getPlausibleResolve() |
| 21 | + expect(resolve({ extension: 'hash' } as any)).toBe('https://plausible.io/js/script.hash.js') |
| 22 | + }) |
| 23 | + |
| 24 | + it('returns default basic plausible.io URL with no options', async () => { |
| 25 | + const resolve = await getPlausibleResolve() |
| 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 | + const resolve = await getPlausibleResolve() |
| 32 | + const selfHosted = 'https://my-self-hosted-plausible.io/js/script.js' |
| 33 | + expect( |
| 34 | + resolve({ scriptId: 'abc123', scriptInput: { src: selfHosted } } as any), |
| 35 | + ).toBe(selfHosted) |
| 36 | + expect( |
| 37 | + resolve({ scriptInput: { src: selfHosted } } as any), |
| 38 | + ).toBe(selfHosted) |
| 39 | + }) |
| 40 | +}) |
0 commit comments