-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next/image): add missing svg test refactor missing types (#65345)
The tests added in #46219 were never correctly testing the headers because `detectContentType()` is called first and only when we can't detect the type from the response body do we fallback to the `Content-Type` header. I also refactored some of the tests because the `ctx: any` type was causing some tests to not run when testing different configuration options. Closes NEXT-3321
- Loading branch information
Showing
11 changed files
with
317 additions
and
107 deletions.
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
4 changes: 1 addition & 3 deletions
4
test/integration/image-optimizer/app/pages/api/application.svg.js
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,6 +1,4 @@ | ||
export default function handler(_req, res) { | ||
res.setHeader('Content-Type', 'application/svg+xml') | ||
res.end( | ||
`<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="60" height="60"><text x="20" y="30">hi</text></svg>` | ||
) | ||
res.end('body is not svg to force fallback to Content-Type header') | ||
} |
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,6 +1,4 @@ | ||
export default function handler(_req, res) { | ||
res.setHeader('Content-Type', 'image/foo, text/html') | ||
res.end( | ||
`<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="60" height="60"><text x="20" y="30">hi</text></svg>` | ||
) | ||
res.end('body is not svg to force fallback to Content-Type header') | ||
} |
19 changes: 19 additions & 0 deletions
19
test/integration/image-optimizer/app/pages/api/stateful/test.png.js
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,19 @@ | ||
const images = [ | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg==', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5/hPwAIAgL/4d1j8wAAAABJRU5ErkJggg==', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P//PwAGBAL/VJiKjgAAAABJRU5ErkJggg==', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', | ||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=', | ||
] | ||
|
||
let state = 0 | ||
|
||
export default function handler(_req, res) { | ||
state++ | ||
const index = state % images.length | ||
const buffer = Buffer.from(images[index], 'base64') | ||
res.setHeader('Content-Type', 'image/png') | ||
return res.end(buffer) | ||
} |
4 changes: 1 addition & 3 deletions
4
test/integration/image-optimizer/app/pages/api/uppercase.svg.js
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,6 +1,4 @@ | ||
export default function handler(_req, res) { | ||
res.setHeader('Content-Type', 'image/SVG+XML') | ||
res.end( | ||
`<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="60" height="60"><text x="20" y="30">hi</text></svg>` | ||
) | ||
res.end('body is not svg to force fallback to Content-Type header') | ||
} |
6 changes: 6 additions & 0 deletions
6
test/integration/image-optimizer/app/pages/api/wrong-header.svg.js
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,6 @@ | ||
export default function handler(_req, res) { | ||
res.setHeader('Content-Type', 'image/png') | ||
res.end( | ||
`<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="60" height="60"><text x="20" y="30">hi</text></svg>` | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
test/integration/image-optimizer/test/dangerously-allow-svg.test.ts
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,13 @@ | ||
import { join } from 'path' | ||
import { setupTests } from './util' | ||
|
||
const appDir = join(__dirname, '../app') | ||
const imagesDir = join(appDir, '.next', 'cache', 'images') | ||
|
||
describe('with dangerouslyAllowSVG config', () => { | ||
setupTests({ | ||
nextConfigImages: { dangerouslyAllowSVG: true }, | ||
appDir, | ||
imagesDir, | ||
}) | ||
}) |
Oops, something went wrong.
3dc2e67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats from current release
Default Build (Increase detected⚠️ )
General Overall increase⚠️
Client Bundles (main, webpack) Overall increase⚠️
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size Overall increase⚠️
Middleware size Overall increase⚠️
Next Runtimes Overall increase⚠️
build cache Overall increase⚠️
Diff details
Diff for page.js
Diff too large to display
Diff for middleware.js
Diff too large to display
Diff for edge-ssr.js
Diff too large to display
Diff for _app-HASH.js
Diff for _error-HASH.js
Diff for amp-HASH.js
Diff for css-HASH.js
Diff for dynamic-HASH.js
Diff for edge-ssr-HASH.js
Diff for head-HASH.js
Diff for hooks-HASH.js
Diff for image-HASH.js
Diff for index-HASH.js
Diff for link-HASH.js
Diff for routerDirect-HASH.js
Diff for script-HASH.js
Diff for withRouter-HASH.js
Diff for 1103-HASH.js
Diff too large to display
Diff for 1a9f679d-HASH.js
Diff too large to display
Diff for 335-HASH.js
Diff for 7953.HASH.js
Diff for framework-HASH.js
Diff for main-HASH.js
Diff too large to display
Diff for main-app-HASH.js
Diff for webpack-HASH.js
Diff for app-page-exp..ntime.dev.js
Diff for app-page-exp..time.prod.js
Diff too large to display
Diff for app-page-tur..time.prod.js
Diff too large to display
Diff for app-page-tur..time.prod.js
Diff too large to display
Diff for app-page.runtime.dev.js
Diff for app-page.runtime.prod.js
Diff too large to display
Diff for app-route-ex..ntime.dev.js
Diff too large to display
Diff for app-route-ex..time.prod.js
Diff too large to display
Diff for app-route-tu..time.prod.js
Diff too large to display
Diff for app-route-tu..time.prod.js
Diff too large to display
Diff for app-route.runtime.dev.js
Diff too large to display
Diff for app-route.ru..time.prod.js
Diff too large to display
Diff for pages-turbo...time.prod.js
Diff too large to display
Diff for pages.runtime.dev.js
Diff too large to display
Diff for pages.runtime.prod.js
Diff too large to display
Diff for server.runtime.prod.js
Diff too large to display