Skip to content

Commit c7c9bcf

Browse files
committed
Add nodejs module test
1 parent 5be82da commit c7c9bcf

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactNode } from 'react'
2+
export default function Root({ children }: { children: ReactNode }) {
3+
return (
4+
<html>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <p>hello world</p>
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('proxy-runtime-nodejs', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
it('should fs.readFile the redirect path from file and redirect to it', async () => {
9+
const browser = await next.browser('/foo')
10+
expect(await browser.elementByCss('p').text()).toBe('hello world')
11+
})
12+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NextRequest, NextResponse } from 'next/server'
2+
// Will not work in edge runtime
3+
import { join } from 'path'
4+
5+
export function proxy(request: NextRequest) {
6+
if (request.nextUrl.pathname === join('/', 'foo')) {
7+
return NextResponse.redirect(new URL('/', request.url))
8+
}
9+
10+
return NextResponse.next()
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/foo

0 commit comments

Comments
 (0)