Skip to content

Commit 67d596c

Browse files
committed
chore: Add Storybook to e2e test playground
1 parent daf09e6 commit 67d596c

File tree

8 files changed

+4486
-628
lines changed

8 files changed

+4486
-628
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ package-lock.json
1010
.turbo/
1111
.vercel
1212
.tsbuildinfo
13+
14+
*storybook.log

packages/e2e/.storybook/main.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { StorybookConfig } from '@storybook/nextjs'
2+
3+
import { join, dirname } from 'path'
4+
5+
/**
6+
* This function is used to resolve the absolute path of a package.
7+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
8+
*/
9+
function getAbsolutePath(value: string): any {
10+
return dirname(require.resolve(join(value, 'package.json')))
11+
}
12+
const config: StorybookConfig = {
13+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
14+
addons: [
15+
getAbsolutePath('@storybook/addon-onboarding'),
16+
getAbsolutePath('@storybook/addon-essentials'),
17+
getAbsolutePath('@chromatic-com/storybook'),
18+
getAbsolutePath('@storybook/addon-interactions')
19+
],
20+
framework: {
21+
name: getAbsolutePath('@storybook/nextjs'),
22+
options: {}
23+
}
24+
}
25+
export default config

packages/e2e/package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"pretest": "cypress install",
1818
"test": "start-server-and-test start http://localhost:3001${BASE_PATH} cypress:run",
1919
"cypress:open": "cypress open",
20-
"cypress:run": "cypress run --headless"
20+
"cypress:run": "cypress run --headless",
21+
"storybook": "storybook dev -p 6006",
22+
"build-storybook": "storybook build"
2123
},
2224
"dependencies": {
2325
"next": "14.2.15",
@@ -26,6 +28,14 @@
2628
"react-dom": "catalog:react19rc"
2729
},
2830
"devDependencies": {
31+
"@chromatic-com/storybook": "^3.2.2",
32+
"@storybook/addon-essentials": "^8.4.2",
33+
"@storybook/addon-interactions": "^8.4.2",
34+
"@storybook/addon-onboarding": "^8.4.2",
35+
"@storybook/blocks": "^8.4.2",
36+
"@storybook/nextjs": "^8.4.2",
37+
"@storybook/react": "^8.4.2",
38+
"@storybook/test": "^8.4.2",
2939
"@types/node": "^22.7.5",
3040
"@types/react": "^18.3.11",
3141
"@types/react-dom": "^18.3.0",
@@ -36,6 +46,7 @@
3646
"cypress-terminal-report": "^7.0.3",
3747
"semver": "^7.6.3",
3848
"start-server-and-test": "^2.0.8",
49+
"storybook": "^8.4.2",
3950
"typescript": "^5.6.3"
4051
}
4152
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NuqsAdapter } from 'nuqs/adapters/next'
2+
import { Page as PageComponent } from './Page'
3+
4+
export default {
5+
title: 'Pages/Cache',
6+
component: PageComponent,
7+
parameters: {
8+
layout: 'fullscreen',
9+
nextjs: {
10+
appDirectory: true
11+
}
12+
},
13+
features: {
14+
experimentalRSC: true
15+
}
16+
}
17+
18+
export const Page = async () => {
19+
return (
20+
<NuqsAdapter>
21+
<PageComponent searchParams={Promise.resolve({ query: 'search term' })} />
22+
</NuqsAdapter>
23+
)
24+
}

packages/e2e/src/stories/Page.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { SearchParams } from 'nuqs/server'
2+
import { NestedComponent } from './nested-component'
3+
import { searchParamsCache } from './search-params'
4+
5+
export async function Page({
6+
searchParams
7+
}: {
8+
searchParams: Promise<SearchParams>
9+
}) {
10+
const parsed = await searchParamsCache.parse(searchParams)
11+
console.dir(parsed)
12+
return <NestedComponent />
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { searchParamsCache } from './search-params'
2+
3+
export const NestedComponent = () => {
4+
const all = searchParamsCache.all()
5+
return <pre>{JSON.stringify(all)}</pre>
6+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {
2+
createSearchParamsCache,
3+
parseAsInteger,
4+
parseAsString
5+
} from 'nuqs/server'
6+
7+
export const searchParamsCache = createSearchParamsCache({
8+
foo: parseAsString,
9+
bar: parseAsInteger.withDefault(0)
10+
})

pnpm-lock.yaml

+4,394-627
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)