generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add API routes e2e test for loaders
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>` | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters