fix: next/jest does not support import.meta #91
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🖖 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/speed-insights build
Then:
For Nextjs 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
For Sveltekit app
VITE_VERCEL_OBSERVABILITY_BASEPATH="/hij" pnpm -F svelte build pnpm -F svelte preview
browse to http://localhost:4173 and check your console: it's trying (and failing) to download
/hij/insights/script.js
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
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
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
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.🔗 Related PRs