From 60799975c6406c3ea7dd926d5dfeb0f8eae28153 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 24 Sep 2024 22:38:59 -0700 Subject: [PATCH] Add test suite --- test/e2e/app-dir/use-cache/app/layout.tsx | 7 +++++++ test/e2e/app-dir/use-cache/app/page.tsx | 21 ++++++++++++++++++++ test/e2e/app-dir/use-cache/next.config.js | 10 ++++++++++ test/e2e/app-dir/use-cache/use-cache.test.ts | 13 ++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/e2e/app-dir/use-cache/app/layout.tsx create mode 100644 test/e2e/app-dir/use-cache/app/page.tsx create mode 100644 test/e2e/app-dir/use-cache/next.config.js create mode 100644 test/e2e/app-dir/use-cache/use-cache.test.ts diff --git a/test/e2e/app-dir/use-cache/app/layout.tsx b/test/e2e/app-dir/use-cache/app/layout.tsx new file mode 100644 index 00000000000000..e7077399c03ce1 --- /dev/null +++ b/test/e2e/app-dir/use-cache/app/layout.tsx @@ -0,0 +1,7 @@ +export default function Root({ children }: { children: React.ReactNode }) { + return ( + + {children} + + ) +} diff --git a/test/e2e/app-dir/use-cache/app/page.tsx b/test/e2e/app-dir/use-cache/app/page.tsx new file mode 100644 index 00000000000000..aa07087da00418 --- /dev/null +++ b/test/e2e/app-dir/use-cache/app/page.tsx @@ -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 ( +

+ {values.x} - {values.y} +

+ ) +} diff --git a/test/e2e/app-dir/use-cache/next.config.js b/test/e2e/app-dir/use-cache/next.config.js new file mode 100644 index 00000000000000..ac4afcf4321968 --- /dev/null +++ b/test/e2e/app-dir/use-cache/next.config.js @@ -0,0 +1,10 @@ +/** + * @type {import('next').NextConfig} + */ +const nextConfig = { + experimental: { + dynamicIO: true, + }, +} + +module.exports = nextConfig diff --git a/test/e2e/app-dir/use-cache/use-cache.test.ts b/test/e2e/app-dir/use-cache/use-cache.test.ts new file mode 100644 index 00000000000000..96a7d6e1d4c410 --- /dev/null +++ b/test/e2e/app-dir/use-cache/use-cache.test.ts @@ -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') + }) +})