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.JS 12 components testing failing with TypeError: Cannot read property 'traceChild' of undefined #18648

Merged
merged 4 commits into from
Oct 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions npm/react/plugins/next/getRunWebpackSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import type { Span } from 'next/dist/telemetry/trace/trace'
// Starting with v11.1.1, a trace is required.
// 'next/dist/telemetry/trace/trace' only exists since v10.0.9
// and our peerDeps support back to v8 so try-catch this import
// Starting from 12.0 trace is now located in 'next/dist/trace/trace'
export async function getRunWebpackSpan (): Promise<{ runWebpackSpan?: Span }> {
let trace: (name: string) => Span

try {
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)
try {
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)

return { runWebpackSpan: trace('cypress') }
return { runWebpackSpan: trace('cypress') }
}
catch (_){
trace = await import('next/dist/trace/trace').then((m) => m.trace)
pbilyk marked this conversation as resolved.
Show resolved Hide resolved

return { runWebpackSpan: trace('cypress') }
}
} catch (_) {
return {}
}
Expand Down