@@ -23,10 +23,11 @@ const imagesDir = join(appDir, '.next', 'cache', 'images')
23
23
const nextConfig = new File ( join ( appDir , 'next.config.js' ) )
24
24
const largeSize = 1080 // defaults defined in server/config.ts
25
25
let nextOutput
26
+ let buildOutput
26
27
let appPort
27
28
let app
28
-
29
- const sharpMissingText = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
29
+ const sharpRuntimeWarning = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
30
+ const sharpBuildWarning = 'Detected `next/image` usage without `sharp`.'
30
31
31
32
async function fsToJson ( dir , output = { } ) {
32
33
const files = await fs . readdir ( dir )
@@ -726,13 +727,29 @@ function runTests({ w, isDev, domains = [], ttl, isSharp }) {
726
727
expect ( Object . keys ( json1 ) . length ) . toBe ( 1 )
727
728
} )
728
729
729
- if ( isDev || isSharp ) {
730
- it ( 'should not have sharp missing warning' , ( ) => {
731
- expect ( nextOutput ) . not . toContain ( sharpMissingText )
730
+ if ( isDev ) {
731
+ it ( 'should not have runtime warning in dev' , ( ) => {
732
+ expect ( nextOutput ) . not . toContain ( sharpRuntimeWarning )
733
+ } )
734
+
735
+ it ( 'should not have build warning in dev' , ( ) => {
736
+ expect ( buildOutput ) . not . toContain ( sharpBuildWarning )
737
+ } )
738
+ } else if ( isSharp ) {
739
+ it ( 'should not have runtime warning when sharp is installed' , ( ) => {
740
+ expect ( nextOutput ) . not . toContain ( sharpRuntimeWarning )
741
+ } )
742
+
743
+ it ( 'should not have build warning when sharp is installed' , ( ) => {
744
+ expect ( buildOutput ) . not . toContain ( sharpBuildWarning )
732
745
} )
733
746
} else {
734
- it ( 'should have sharp missing warning' , ( ) => {
735
- expect ( nextOutput ) . toContain ( sharpMissingText )
747
+ it ( 'should have runtime warning when sharp is not installed' , ( ) => {
748
+ expect ( nextOutput ) . toContain ( sharpRuntimeWarning )
749
+ } )
750
+
751
+ it ( 'should have build warning when sharp is not installed' , ( ) => {
752
+ expect ( buildOutput ) . toContain ( sharpBuildWarning )
736
753
} )
737
754
}
738
755
}
@@ -910,8 +927,10 @@ describe('Image Optimizer', () => {
910
927
} ,
911
928
} )
912
929
nextOutput = ''
930
+ buildOutput = ''
913
931
nextConfig . replace ( '{ /* replaceme */ }' , json )
914
- await nextBuild ( appDir )
932
+ const out = await nextBuild ( appDir , [ ] , { stderr : true } )
933
+ buildOutput = out . stderr
915
934
appPort = await findPort ( )
916
935
app = await nextStart ( appDir , appPort , {
917
936
onStderr ( msg ) {
@@ -949,7 +968,8 @@ describe('Image Optimizer', () => {
949
968
},
950
969
}`
951
970
)
952
- await nextBuild ( appDir )
971
+ const out = await nextBuild ( appDir , [ ] , { stderr : true } )
972
+ buildOutput = out . stderr
953
973
appPort = await findPort ( )
954
974
app = await nextStart ( appDir , appPort )
955
975
} )
@@ -1025,7 +1045,8 @@ describe('Image Optimizer', () => {
1025
1045
},
1026
1046
}`
1027
1047
nextConfig . replace ( '{ /* replaceme */ }' , newConfig )
1028
- await nextBuild ( appDir )
1048
+ const out = await nextBuild ( appDir , [ ] , { stderr : true } )
1049
+ buildOutput = out . stderr
1029
1050
appPort = await findPort ( )
1030
1051
app = await nextStart ( appDir , appPort )
1031
1052
} )
@@ -1084,6 +1105,7 @@ describe('Image Optimizer', () => {
1084
1105
const size = 384 // defaults defined in server/config.ts
1085
1106
beforeAll ( async ( ) => {
1086
1107
nextOutput = ''
1108
+ buildOutput = ''
1087
1109
appPort = await findPort ( )
1088
1110
app = await launchApp ( appDir , appPort , {
1089
1111
onStderr ( msg ) {
@@ -1111,6 +1133,7 @@ describe('Image Optimizer', () => {
1111
1133
} ,
1112
1134
} )
1113
1135
nextOutput = ''
1136
+ buildOutput = ''
1114
1137
nextConfig . replace ( '{ /* replaceme */ }' , json )
1115
1138
appPort = await findPort ( )
1116
1139
app = await launchApp ( appDir , appPort , {
@@ -1133,7 +1156,9 @@ describe('Image Optimizer', () => {
1133
1156
const size = 384 // defaults defined in server/config.ts
1134
1157
beforeAll ( async ( ) => {
1135
1158
nextOutput = ''
1136
- await nextBuild ( appDir )
1159
+ buildOutput = ''
1160
+ const out = await nextBuild ( appDir , [ ] , { stderr : true } )
1161
+ buildOutput = out . stderr
1137
1162
appPort = await findPort ( )
1138
1163
app = await nextStart ( appDir , appPort , {
1139
1164
onStderr ( msg ) {
@@ -1167,8 +1192,10 @@ describe('Image Optimizer', () => {
1167
1192
} ,
1168
1193
} )
1169
1194
nextOutput = ''
1195
+ buildOutput = ''
1170
1196
nextConfig . replace ( '{ /* replaceme */ }' , json )
1171
- await nextBuild ( appDir )
1197
+ const out = await nextBuild ( appDir , [ ] , { stderr : true } )
1198
+ buildOutput = out . stderr
1172
1199
appPort = await findPort ( )
1173
1200
app = await nextStart ( appDir , appPort , {
1174
1201
onStderr ( msg ) {
0 commit comments