Skip to content

Commit

Permalink
fix test should fail when internal url is not an image
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed May 15, 2024
1 parent 1560201 commit 339852c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/integration/image-optimizer/app/pages/api/no-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function handler(_req, res) {
// Intentionally missing Content-Type header so that
// the fallback is not served when optimization fails
res.end('foo')
}
6 changes: 4 additions & 2 deletions test/integration/image-optimizer/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,13 @@ export function runTests(ctx: RunTestsCtx) {
const query = { url: `//example.com`, w: ctx.w, q: 1 }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
expect(res.status).toBe(400)
expect(await res.text()).toBe(`"url" parameter cannot be a protocol-relative URL (//)`)
expect(await res.text()).toBe(
`"url" parameter cannot be a protocol-relative URL (//)`
)
})

it('should fail when internal url is not an image', async () => {
const url = `//<h1>not-an-image</h1>`
const url = `/api/no-header`
const query = { url, w: ctx.w, q: 39 }
const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
Expand Down

0 comments on commit 339852c

Please sign in to comment.