Skip to content

Commit

Permalink
Add test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Sep 25, 2024
1 parent 6c2021f commit 6079997
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/e2e/app-dir/use-cache/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
21 changes: 21 additions & 0 deletions test/e2e/app-dir/use-cache/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function getCachedRandom(x: number) {
'use cache'
return {
x,
y: Math.random(),
}
}

export default async function Page({
searchParams,
}: {
searchParams: Promise<{ n: string }>
}) {
const n = +(await searchParams).n
const values = getCachedRandom(n)
return (
<p id="output">
{values.x} - {values.y}
</p>
)
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/use-cache/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
dynamicIO: true,
},
}

module.exports = nextConfig
13 changes: 13 additions & 0 deletions test/e2e/app-dir/use-cache/use-cache.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import { nextTestSetup } from 'e2e-utils'

describe('use-cache', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should cache results', async () => {
const browser = await next.browser('/')
expect(await browser.waitForElementByCss('#output').text()).toBe('hello')
})
})

0 comments on commit 6079997

Please sign in to comment.