@@ -18,6 +18,11 @@ const sharp = require(`sharp`)
18
18
fs . ensureDirSync = jest . fn ( )
19
19
fs . existsSync = jest . fn ( ) . mockReturnValue ( false )
20
20
21
+ const decodeBase64PngAsRaw = async png =>
22
+ sharp ( Buffer . from ( png . replace ( `data:image/png;base64,` , `` ) , `base64` ) )
23
+ . raw ( )
24
+ . toBuffer ( )
25
+
21
26
const {
22
27
base64,
23
28
generateBase64,
@@ -136,10 +141,13 @@ describe(`gatsby-plugin-sharp`, () => {
136
141
} )
137
142
138
143
it ( `includes responsive image properties, e.g. sizes, srcset, etc.` , async ( ) => {
139
- const result = await fluid ( { file } )
144
+ const { base64 , ... result } = await fluid ( { file } )
140
145
141
146
expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
142
147
expect ( result ) . toMatchSnapshot ( )
148
+
149
+ const rawPixelData = await decodeBase64PngAsRaw ( base64 )
150
+ expect ( rawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
143
151
} )
144
152
145
153
it ( `adds pathPrefix if defined` , async ( ) => {
@@ -400,12 +408,15 @@ describe(`gatsby-plugin-sharp`, () => {
400
408
401
409
describe ( `base64` , ( ) => {
402
410
it ( `converts image to base64` , async ( ) => {
403
- const result = await base64 ( {
411
+ const { src , ... result } = await base64 ( {
404
412
file,
405
413
args,
406
414
} )
407
415
408
416
expect ( result ) . toMatchSnapshot ( )
417
+
418
+ const rawPixelData = await decodeBase64PngAsRaw ( src )
419
+ expect ( rawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
409
420
} )
410
421
411
422
it ( `should cache same image` , async ( ) => {
@@ -597,25 +608,31 @@ describe(`gatsby-plugin-sharp`, () => {
597
608
base64 : false ,
598
609
}
599
610
600
- const fixedSvg = await fixed ( {
611
+ const { tracedSVG : fixedTracedSVG , ... fixedSvg } = await fixed ( {
601
612
file,
602
613
args,
603
614
} )
604
615
605
616
expect ( fixedSvg ) . toMatchSnapshot ( `fixed` )
606
617
607
- expect ( fixedSvg . tracedSVG ) . toMatch ( `data:image/png;base64` )
608
- expect ( fixedSvg . tracedSVG ) . not . toMatch ( `data:image/svg+xml` )
618
+ expect ( fixedTracedSVG ) . toMatch ( `data:image/png;base64` )
619
+ expect ( fixedTracedSVG ) . not . toMatch ( `data:image/svg+xml` )
620
+
621
+ const fixedRawPixelData = await decodeBase64PngAsRaw ( fixedTracedSVG )
622
+ expect ( fixedRawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
609
623
610
- const fluidSvg = await fluid ( {
624
+ const { tracedSVG : fluidTracedSVG , ... fluidSvg } = await fluid ( {
611
625
file,
612
626
args,
613
627
} )
614
628
615
629
expect ( fluidSvg ) . toMatchSnapshot ( `fluid` )
616
630
617
- expect ( fluidSvg . tracedSVG ) . toMatch ( `data:image/png;base64` )
618
- expect ( fluidSvg . tracedSVG ) . not . toMatch ( `data:image/svg+xml` )
631
+ expect ( fluidTracedSVG ) . toMatch ( `data:image/png;base64` )
632
+ expect ( fluidTracedSVG ) . not . toMatch ( `data:image/svg+xml` )
633
+
634
+ const fluidRawPixelData = await decodeBase64PngAsRaw ( fluidTracedSVG )
635
+ expect ( fluidRawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
619
636
} )
620
637
} )
621
638
@@ -627,13 +644,20 @@ describe(`gatsby-plugin-sharp`, () => {
627
644
}
628
645
629
646
it ( `fixed` , async ( ) => {
630
- const result = await fixed ( { file, args } )
647
+ const { base64, ...result } = await fixed ( { file, args } )
648
+
631
649
expect ( result ) . toMatchSnapshot ( )
650
+
651
+ const rawPixelData = await decodeBase64PngAsRaw ( base64 )
652
+ expect ( rawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
632
653
} )
633
654
634
655
it ( `fluid` , async ( ) => {
635
- const result = await fluid ( { file, args } )
656
+ const { base64 , ... result } = await fluid ( { file, args } )
636
657
expect ( result ) . toMatchSnapshot ( )
658
+
659
+ const rawPixelData = await decodeBase64PngAsRaw ( base64 )
660
+ expect ( rawPixelData . toString ( `hex` ) ) . toMatchSnapshot ( )
637
661
} )
638
662
639
663
it ( `creates two different images for different duotone settings` , async ( ) => {
0 commit comments