Skip to content

Commit

Permalink
test: add basic tests for error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Dec 6, 2024
1 parent fb39f25 commit 9a575b8
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function Inner() {

async function foo() {
await setTimeout(0)
unstable_after(function aboveBar() {
unstable_after(() => {
return bar()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ function Wrapper() {
}

function Inner() {
bar()
foo()
return null
}

function bar() {
unstable_after(function aboveZap() {
return zap()
function foo() {
unstable_after(() => {
return bar()
})
}

async function zap() {
async function bar() {
await setTimeout(0)
throws()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export const metadata = {
description: 'Generated by Next.js',
}

// TODO: check build-time errors if we allow something static
export const dynamic = 'force-dynamic'

export default function RootLayout({ children }) {
return (
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ function Inner() {
return null
}

// this should bail out, otherwise it'll likely be incorrect

async function foo() {
await setTimeout(0)
function foo() {
unstable_after(bar())
}

async function bar() {
await setTimeout(0)
unstable_after(zap())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { unstable_after } from 'next/server'
import { setTimeout } from 'timers/promises'

export default function Page() {
return <Wrapper />
}

function Wrapper() {
return <Inner />
}

function Inner() {
foo()
return null
}

function foo() {
unstable_after(bar())
}

async function bar() {
// TODO(after): it looks like `aboveZap` is not in the stack if `zap` does `setTimeout(0)`?
unstable_after(function aboveZap() {
return zap()
})
}

async function zap() {
await setTimeout(0)
throws()
}

function throws() {
throw new Error('kaboom')
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function Wrapper() {
return <Inner />
}

function Inner() {
foo()
async function Inner() {
await foo()
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function Wrapper() {
return <Inner />
}

function Inner() {
foo()
async function Inner() {
await foo()
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Inner() {
return null
}

async function foo() {
function foo() {
unstable_after(bar())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { unstable_after } from 'next/server'

export default function Page() {
return <Wrapper />
}

function Wrapper() {
return <Inner />
}

async function Inner() {
await foo()
return null
}

async function foo() {
unstable_after(bar())
}

async function bar() {
unstable_after(function aboveZap() {
return zap()
})
}

async function zap() {
throws()
}

function throws() {
throw new Error('kaboom')
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Inner() {
function helper() {
unstable_after(
(async () => {
await setTimeout(500)
await setTimeout(0)
nestedHelper()
})()
)
Expand All @@ -26,7 +26,7 @@ function helper() {
function nestedHelper() {
unstable_after(
(async () => {
await setTimeout(500)
await setTimeout(0)
throws()
})()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ function Inner() {

function helper() {
unstable_after(async function aboveNestedHelper() {
await setTimeout(500)
await setTimeout(0)
nestedHelper()
})
}

function nestedHelper() {
unstable_after(async function aboveThrows() {
await setTimeout(500)
await setTimeout(0)
throws()
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { unstable_after } from 'next/server'
import { setTimeout } from 'timers/promises'

export default function Page() {
return <Wrapper />
}

function Wrapper() {
return <Inner />
}

function Inner() {
helper()
return null
}

function helper() {
unstable_after(async () => {
await setTimeout(0)
throws()
})
}

function throws() {
throw new Error('kaboom')
}
Loading

0 comments on commit 9a575b8

Please sign in to comment.