Skip to content

Commit

Permalink
test: Add API routes e2e test for loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Dec 26, 2024
1 parent 69056d9 commit d4c52d2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/e2e/next/cypress/e2e/shared/loader.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { testLoader } from 'e2e-shared/specs/loader.cy'

// In page components:

testLoader({ path: '/app/loader', nextJsRouter: 'app' })

testLoader({ path: '/pages/loader', nextJsRouter: 'pages' })

// In API routes:

testLoader({ path: '/api/app/loader', nextJsRouter: 'app' })

testLoader({ path: '/api/pages/loader', nextJsRouter: 'pages' })
21 changes: 21 additions & 0 deletions packages/e2e/next/src/app/api/app/loader/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { loadSearchParams } from 'e2e-shared/specs/loader'
import { NextResponse } from 'next/server'

export async function GET(request: Request) {
const { test, int } = loadSearchParams(request)
return new NextResponse(
`<!doctype html>
<html>
<body>
<div id="hydration-marker" style="display:none;" aria-hidden>hydrated</div>
<pre id="test">${test}</pre>
<pre id="int">${int}</pre>
</body>
</html>`,
{
headers: {
'content-type': 'text/html'
}
}
)
}
22 changes: 22 additions & 0 deletions packages/e2e/next/src/pages/api/pages/loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { loadSearchParams } from 'e2e-shared/specs/loader'
import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(
request: NextApiRequest,
response: NextApiResponse
) {
const { test, int } = loadSearchParams(request.query)
response
.status(200)
.setHeader('content-type', 'text/html')
.send(
`<!doctype html>
<html>
<body>
<div id="hydration-marker" style="display:none;" aria-hidden>hydrated</div>
<pre id="test">${test}</pre>
<pre id="int">${int}</pre>
</body>
</html>`
)
}
2 changes: 1 addition & 1 deletion packages/e2e/next/src/pages/pages/loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
LoaderRenderer,
loadSearchParams
} from 'e2e-shared/specs/loader'
import { GetServerSidePropsContext } from 'next'
import type { GetServerSidePropsContext } from 'next'

type PageProps = {
serverValues: SearchParams
Expand Down

0 comments on commit d4c52d2

Please sign in to comment.