Skip to content

Commit

Permalink
Expand server-source-maps scenarios to cover Edge runtime
Browse files Browse the repository at this point in the history
...and use test patterns more consistently
  • Loading branch information
eps1lon committed Nov 8, 2024
1 parent 98064fa commit f2c96cc
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 143 deletions.
39 changes: 0 additions & 39 deletions test/development/app-render-error-log/app-render-error-log.test.ts

This file was deleted.

8 changes: 0 additions & 8 deletions test/development/app-render-error-log/app/edge/page.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions test/development/app-render-error-log/app/fn.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/development/app-render-error-log/app/layout.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions test/development/app-render-error-log/app/page.tsx

This file was deleted.

1 change: 0 additions & 1 deletion test/development/app-render-error-log/next.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Suspense } from 'react'

export default function Root({ children }) {
return (
<html>
<body>{children}</body>
<body>
<Suspense>{children}</Suspense>
</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { connection } from 'next/server'

function logError(cause) {
const error = new Error('Boom', { cause })
console.error(error)
}

export default function Page() {
export default async function Page() {
await connection()

const error = new Error('Boom')
logError(error)
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { connection } from 'next/server'

class UnnamedError extends Error {}
class NamedError extends Error {
name = 'MyError'
}

export default function Page() {
export default async function Page() {
await connection()

console.error(new UnnamedError('Foo'))
console.error(new NamedError('Bar'))
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { connection } from 'next/server'
import { run } from 'internal-pkg'

function logError() {
const error = new Error('Boom')
console.error(error)
}

export default function Page() {
export default async function Page() {
await connection()

run(() => logError())
return null
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { connection } from 'next/server'

function logError() {
const error = new Error('Boom')
console.error(error)
}

export default function Page() {
export default async function Page() {
await connection()

logError()
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

function throwError() {
throw new Error('Boom')
}

export function Thrower() {
throwError()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { connection } from 'next/server'
import { Thrower } from './Thrower'

export default async function Page() {
await connection()
return <Thrower />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const runtime = 'edge'

export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use client'

function logError() {
const error = new Error('Boom')
console.error(error)
console.error(new Error('Boom'))
}

export default function Page() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function throwError() {
throw new Error('Boom')
}

export default function Page() {
throwError()
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use client'

function throwError() {
throw new Error('Boom')
}

export default function Page() {
throwError()
return null
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/server-source-maps/fixtures/edge/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
serverSourceMaps: true,
},
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable jest/no-standalone-expect */
import * as path from 'path'
import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi'
import { retry } from 'next-test-utils'

function normalizeCliOutput(output: string) {
return stripAnsi(output)
}

describe('app-dir - server source maps edge runtime', () => {
const { skipped, next, isNextDev, isTurbopack } = nextTestSetup({
files: path.join(__dirname, 'fixtures/edge'),
// Deploy tests don't have access to runtime logs.
// Manually verify that the runtime logs match.
skipDeployment: true,
})

if (skipped) return

it('logged errors have a sourcemapped stack with a codeframe', async () => {
const outputIndex = next.cliOutput.length
await next.render('/rsc-error-log')

if (isNextDev) {
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toContain('Error: Boom')
})
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
isTurbopack
? // TODO(veil): Error stack should be printed
'\n[Error: Boom]\n'
: // TODO(veil): Error stack should be printed
'\n[Error: Boom]\n'
)
} else {
// TODO: Test `next build` with `--enable-source-maps`.
}
})

it('thrown SSR errors', async () => {
const outputIndex = next.cliOutput.length
await next.render('/ssr-throw')

if (isNextDev) {
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toContain('Error: Boom')
})

const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain(
isTurbopack
? '\n ⨯ Error: Boom' +
'\n at throwError (./app/ssr-throw/page.js:4:9)' +
'\n at Page (./app/ssr-throw/page.js:8:3)' +
'\ndigest: "'
: '\n ⨯ Error: Boom' +
'\n at throwError (./app/ssr-throw/page.js:6:11)' +
'\n at Page (./app/ssr-throw/page.js:9:5)' +
'\ndigest: "'
)
expect(cliOutput).toMatch(/digest: "\d+"/)
} else {
// TODO: Test `next build` with `--enable-source-maps`.
}
})

it('should log the correct values on app-render error', async () => {
const outputIndex = next.cliOutput.length
await next.fetch('/rsc-throw')

if (isNextDev) {
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toMatch(/Error: Boom/)
})

const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
// TODO(veil): Hide Node.js internal stackframes
expect(cliOutput).toContain(
isTurbopack
? '\n ⨯ Error: Boom' +
'\n at throwError (./app/rsc-throw/page.js:2:9)' +
'\n at Page (./app/rsc-throw/page.js:6:3)' +
// TODO(veil): Hide Node.js internal stackframes
'\n at AsyncLocalStorage.run (node:async_hooks:346:14)' +
'\ndigest: "'
: '\n ⨯ Error: Boom' +
'\n at throwError (./app/rsc-throw/page.js:6:11)' +
'\n at Page (./app/rsc-throw/page.js:9:5)' +
// TODO(veil): Hide Node.js internal stackframes
'\n at AsyncLocalStorage.run (node:async_hooks:346:14)' +
'\ndigest: "'
)
expect(cliOutput).toMatch(/digest: "\d+"/)
} else {
// TODO: Test `next build` with `--enable-source-maps`.
}
})
})
Loading

0 comments on commit f2c96cc

Please sign in to comment.