Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: next/jest does not support import.meta #162

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

feugy
Copy link
Member

@feugy feugy commented Nov 25, 2024

🖖 What's in there?

We found out our package breaks Next.js test, because its Jest configuration doesn't support import.meta.
This PR fixes it.

🤺 How to test?

To reproduce locally, and set custom basepath:

pnpm i && pnpm -F @vercel/analytics build 

Then:

  1. For Nextjs 14 app

    NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH="/abc" pnpm -F nextjs build
    pnpm -F nextjs start

    browse to http://localhost:3000 and check your console: it's trying (and failing) to download /abc/insights/script.js

  2. For Nextjs 15 app

    NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH="/def" pnpm -F nextjs-15 build
    pnpm -F nextjs-15 start

    browse to http://localhost:3000 and check your console: it's trying (and failing) to download /def/insights/script.js

  3. For Sveltekit app

    VITE_VERCEL_OBSERVABILITY_BASEPATH="/hij" pnpm -F sveltekit build
    pnpm -F sveltekit preview

    browse to http://localhost:4173 and check your console: it's trying (and failing) to download /hij/insights/script.js

  4. For vue app

    VITE_VERCEL_OBSERVABILITY_BASEPATH="/klm" pnpm -F vue build
    pnpm -F vue preview

    browse to http://localhost:4173 and check your console: it's trying (and failing) to download /klm/insights/script.js

  5. For nuxt app

    VITE_VERCEL_OBSERVABILITY_BASEPATH="/nop" pnpm -F nuxt build
    pnpm -F nuxt preview

    browse to http://localhost:3000 and check your console: it's trying (and failing) to download /nop/insights/script.js

  6. For remix app

    VITE_VERCEL_OBSERVABILITY_BASEPATH="/qrs" pnpm -F remix build
    pnpm -F remix start

    browse to http://localhost:3000 and check your console: it's trying (and failing) to download /qrs/insights/script.js

  7. For astro app

    PUBLIC_VERCEL_OBSERVABILITY_BASEPATH="/tuv" pnpm -F astro build
    pnpm -F astro preview

    browse to http://localhost:4321 and check your console: it's trying (and failing) to download /tuv/insights/script.js

There is no example for CRA.

🔬Notes to reviewers

Rather than altering jest configuration for next, I've split the getBasePath() function so each framework has its own implementation.

I've moved the React component into its own folder as we do for speed-insights.

🔗 Related PRs

@feugy feugy requested a review from a team November 25, 2024 11:14
Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
analytics-astro ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-next15 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-nuxt ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-remix ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-sveltekit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am
analytics-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2024 11:19am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant