Skip to content

Commit

Permalink
Add nested cache test case
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 21, 2025
1 parent 4f9f1dd commit 2151b79
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { setTimeout } from 'timers/promises'

async function getUncachedData() {
await setTimeout(0)

return Math.random()
}

const getCachedData = async (promise: Promise<number>) => {
'use cache'

return await promise
}

async function indirection(promise: Promise<number>) {
'use cache'

return getCachedData(promise)
}

export default async function Page() {
const data = await indirection(getUncachedData())

return <p>{data}</p>
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ describe('use-cache-hanging-inputs', () => {
}, 180_000)
})

describe('when an uncached promise is used inside of a nested "use cache"', () => {
it('should show an error toast after a timeout', async () => {
const outputIndex = next.cliOutput.length
const browser = await next.browser('/uncached-promise-nested')

// The request is pending while we stall on the hanging inputs, and
// playwright will wait for the load even before continuing. So we don't
// need to wait for the "use cache" timeout of 50 seconds here.

await openRedbox(browser)

const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser)

expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)

// TODO(veil): This should have an error source if the source mapping works.
expect(errorSource).toBe(null)

const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))

// TODO(veil): Should include properly source mapped stack frames.
expect(cliOutput).toContain(
isTurbopack
? `${expectedErrorMessage}
at [project]/app/uncached-promise-nested/page.tsx [app-rsc] (ecmascript)`
: `${expectedErrorMessage}
at eval (webpack-internal:///(rsc)/./app/uncached-promise-nested/page.tsx:35:97)`
)
}, 180_000)
})

describe('when an error is thrown', () => {
it('should show an error overlay with only one error', async () => {
const browser = await next.browser('/error')
Expand Down Expand Up @@ -132,6 +164,10 @@ describe('use-cache-hanging-inputs', () => {
expect(cliOutput).toInclude(
'Error occurred prerendering page "/uncached-promise"'
)

expect(cliOutput).toInclude(
'Error occurred prerendering page "/uncached-promise-nested"'
)
}, 180_000)
}
})

0 comments on commit 2151b79

Please sign in to comment.