File tree Expand file tree Collapse file tree 4 files changed +54
-3
lines changed
cypress/integration/default Expand file tree Collapse file tree 4 files changed +54
-3
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,27 @@ describe('next/images', () => {
1717 cy . visit ( '/image' )
1818 cy . findByRole ( 'img' , { name : / s h i b a i n u d o g l o o k s t h r o u g h a w i n d o w / i } )
1919 } )
20- } )
20+
21+ it ( 'should show image allow-listed with remotePatterns' , ( ) => {
22+ cy . visit ( '/image' )
23+ cy . findByRole ( 'img' , { name : / t a w n y f r o g m o u t h / i } ) . should ( 'be.visible' ) . and ( ( $img ) => {
24+ // "naturalWidth" and "naturalHeight" are set when the image loads
25+ expect (
26+ $img [ 0 ] . naturalWidth ,
27+ 'image has natural width'
28+ ) . to . be . greaterThan ( 0 )
29+ } )
30+ } )
31+
32+ it ( 'should show a broken image if it is not on domains or remotePatterns allowlist' , ( ) => {
33+ cy . visit ( '/image' )
34+ cy . findByRole ( 'img' , { name : / j e l l y b e a n s / i } ) . should ( 'be.visible' ) . and ( ( $img ) => {
35+ expect (
36+ $img [ 0 ] . style . height
37+ ) . to . equal ( '0px' )
38+ expect (
39+ $img [ 0 ] . style . width
40+ ) . to . equal ( '0px' )
41+ } )
42+ } )
43+ } )
Original file line number Diff line number Diff line change @@ -77,4 +77,13 @@ module.exports = {
7777 sassOptions : {
7878 includePaths : [ path . join ( __dirname , 'styles-sass-test' ) ] ,
7979 } ,
80+ experimental : {
81+ images : {
82+ remotePatterns : [
83+ {
84+ hostname : '*.imgur.com' ,
85+ } ,
86+ ] ,
87+ } ,
88+ } ,
8089}
Original file line number Diff line number Diff line change @@ -14,14 +14,24 @@ const Images = () => (
1414 </ p >
1515 < p >
1616 < Image src = { logo } alt = "netlify logomark" />
17-
1817 < Image
1918 src = "https://raw.githubusercontent.com/netlify/netlify-plugin-nextjs/main/next-on-netlify.png"
2019 alt = "Picture of the author"
2120 width = { 500 }
2221 height = { 500 }
2322 />
23+ < Image src = "https://i.imgur.com/bxSRS3Jb.png" alt = "Tawny Frogmouth" width = { 160 } height = { 160 } />
24+ </ p >
25+
26+ < p >
27+ The following image should be broken as the domain is not added to domains or remotePatterns in next.config.js:
2428 </ p >
29+ < Image
30+ src = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/SIPI_Jelly_Beans_4.1.07.tiff/lossy-page1-256px-SIPI_Jelly_Beans_4.1.07.tiff.jpg"
31+ alt = "Jellybeans"
32+ width = { 146 }
33+ height = { 32 }
34+ />
2535 </ div >
2636)
2737
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const { downloadFile } = require('../plugin/src/templates/handlerUtils')
1616
1717const plugin = require ( '../plugin/src' )
1818
19- const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME } = require ( '../plugin/src/constants' )
19+ const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME } = require ( '../plugin/src/constants' )
2020const { join } = require ( 'pathe' )
2121const {
2222 matchMiddleware,
@@ -527,6 +527,15 @@ describe('onBuild()', () => {
527527 // The function is supposed to return undefined, but we want to check if it throws
528528 expect ( await plugin . onBuild ( defaultArgs ) ) . toBeUndefined ( )
529529 } )
530+
531+ test ( 'generates imageconfig file with entries for domains and remotePatterns' , async ( ) => {
532+ await moveNextDist ( )
533+ await plugin . onBuild ( defaultArgs )
534+ const imageConfigPath = path . join ( constants . INTERNAL_FUNCTIONS_SRC , IMAGE_FUNCTION_NAME , 'imageconfig.json' )
535+ const imageConfigJson = await readJson ( imageConfigPath )
536+ expect ( imageConfigJson . domains . length ) . toBe ( 1 )
537+ expect ( imageConfigJson . remotePatterns . length ) . toBe ( 1 )
538+ } )
530539} )
531540
532541describe ( 'onPostBuild' , ( ) => {
You can’t perform that action at this time.
0 commit comments