Skip to content

Commit

Permalink
tests: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Mar 4, 2024
1 parent 3553e7c commit b159a9d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/e2e/app-dir/dynamic-data/dynamic-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ createNextDescribe(

expect($('#searchparams .foo').text()).toBe('foosearch')
})

it('should track dynamic apis when rendering app routes', async () => {
expect(next.cliOutput).toContain(
`Caught Error: Dynamic server usage: Route /routes/url couldn't be rendered statically because it accessed \`request.url\`.`
)
expect(next.cliOutput).toContain(
`Caught Error: Dynamic server usage: Route /routes/next-url couldn't be rendered statically because it accessed \`nextUrl.toString\`.`
)
})
}
)

Expand Down Expand Up @@ -227,6 +236,12 @@ createNextDescribe(
expect(next.cliOutput).toMatch(
'Error: Route /search with `dynamic = "error"` couldn\'t be rendered statically because it used `searchParams`.'
)
expect(next.cliOutput).toMatch(
'Error: Route /routes/form-data/error with `dynamic = "error"` couldn\'t be rendered statically because it accessed `request.formData`.'
)
expect(next.cliOutput).toMatch(
'Error: Route /routes/next-url/error with `dynamic = "error"` couldn\'t be rendered statically because it accessed `nextUrl.toString`.'
)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const GET = async (request) => {
try {
const body = JSON.stringify({ pathname: request.nextUrl.toString() })
return new Response(body, {
headers: {
'content-type': 'application/json',
},
})
} catch (err) {
console.log('Caught Error:', err.message)
return new Response(null, { status: 500 })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const GET = async (request) => {
try {
const body = JSON.stringify({ url: request.url })
return new Response(body, {
headers: {
'content-type': 'application/json',
},
})
} catch (err) {
console.log('Caught Error:', err.message)
return new Response(null, { status: 500 })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const dynamic = 'error'

export const GET = async (request) => {
return new Response(
JSON.stringify({ query: request.formData.get('query') }),
{
headers: {
'content-type': 'application/json',
},
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const dynamic = 'error'

export const GET = async (request) => {
return new Response(
JSON.stringify({ pathname: request.nextUrl.toString() }),
{
headers: {
'content-type': 'application/json',
},
}
)
}

0 comments on commit b159a9d

Please sign in to comment.