Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed May 18, 2023
1 parent 776648c commit 95603a2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
const headers = request.headers
return NextResponse.json({
host: headers.get('x-forwarded-host'),
ip: headers.get('x-forwarded-ip'),
port: headers.get('x-forwarded-port'),
proto: headers.get('x-forwarded-proto'),
})
}

export const config = {
matcher: '/headers',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('next').NextConfig} */
module.exports = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useTestHarness } from '@turbo/pack-test-harness'

export default function Foo() {
useTestHarness(runTests)

return 'index'
}

function runTests() {
it('should stream middleware response from node', async () => {
const res = await fetch('/headers')
const json = await res.json()

const { host, port, proto } = json
expect(host).toBe(`localhost:${port}`)
expect(port).toMatch(/\d+/)
expect(proto).toBe('http')
})
}

0 comments on commit 95603a2

Please sign in to comment.