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', () => {
17
17
cy . visit ( '/image' )
18
18
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 } )
19
19
} )
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 = {
77
77
sassOptions : {
78
78
includePaths : [ path . join ( __dirname , 'styles-sass-test' ) ] ,
79
79
} ,
80
+ experimental : {
81
+ images : {
82
+ remotePatterns : [
83
+ {
84
+ hostname : '*.imgur.com' ,
85
+ } ,
86
+ ] ,
87
+ } ,
88
+ } ,
80
89
}
Original file line number Diff line number Diff line change @@ -14,14 +14,24 @@ const Images = () => (
14
14
</ p >
15
15
< p >
16
16
< Image src = { logo } alt = "netlify logomark" />
17
-
18
17
< Image
19
18
src = "https://raw.githubusercontent.com/netlify/netlify-plugin-nextjs/main/next-on-netlify.png"
20
19
alt = "Picture of the author"
21
20
width = { 500 }
22
21
height = { 500 }
23
22
/>
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:
24
28
</ 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
+ />
25
35
</ div >
26
36
)
27
37
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const { downloadFile } = require('../plugin/src/templates/handlerUtils')
16
16
17
17
const plugin = require ( '../plugin/src' )
18
18
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' )
20
20
const { join } = require ( 'pathe' )
21
21
const {
22
22
matchMiddleware,
@@ -527,6 +527,15 @@ describe('onBuild()', () => {
527
527
// The function is supposed to return undefined, but we want to check if it throws
528
528
expect ( await plugin . onBuild ( defaultArgs ) ) . toBeUndefined ( )
529
529
} )
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
+ } )
530
539
} )
531
540
532
541
describe ( 'onPostBuild' , ( ) => {
You can’t perform that action at this time.
0 commit comments