1- const crypto = require ( 'crypto' ) ;
21const path = require ( 'path' ) ;
3-
4- const Jimp = require ( 'jimp' ) ;
2+ const sharp = require ( 'sharp' ) ;
53
64const computeAndInjectDiffs = require ( '../computeAndInjectDiffs' ) ;
75const createDiffImage = require ( '../createDiffImage' ) ;
@@ -11,8 +9,34 @@ let image2;
119let subject ;
1210
1311beforeEach ( async ( ) => {
14- image1 = ( await Jimp . read ( 'http://127.0.0.1:5411/aa-ffffff.png' ) ) . bitmap ;
15- image2 = ( await Jimp . read ( 'http://127.0.0.1:5411/aa-f7f7f7.png' ) ) . bitmap ;
12+ const image1Sharp = sharp (
13+ path . resolve ( __dirname , 'test-images/aa-ffffff.png' ) ,
14+ ) ;
15+ const image2Sharp = sharp (
16+ path . resolve ( __dirname , 'test-images/aa-f7f7f7.png' ) ,
17+ ) ;
18+
19+ const [ image1Metadata , image2Metadata ] = await Promise . all ( [
20+ image1Sharp . metadata ( ) ,
21+ image2Sharp . metadata ( ) ,
22+ ] ) ;
23+
24+ const [ image1Buffer , image2Buffer ] = await Promise . all ( [
25+ image1Sharp . raw ( ) . toBuffer ( ) ,
26+ image2Sharp . raw ( ) . toBuffer ( ) ,
27+ ] ) ;
28+
29+ image1 = {
30+ data : image1Buffer ,
31+ width : image1Metadata . width ,
32+ height : image1Metadata . height ,
33+ } ;
34+ image2 = {
35+ data : image2Buffer ,
36+ width : image2Metadata . width ,
37+ height : image2Metadata . height ,
38+ } ;
39+
1640 subject = ( ) =>
1741 createDiffImage (
1842 computeAndInjectDiffs ( {
@@ -24,14 +48,39 @@ beforeEach(async () => {
2448
2549it ( 'has a total diff value and a max diff' , async ( ) => {
2650 const { diff, maxDiff } = await subject ( ) ;
27- expect ( diff ) . toEqual ( 0.000013924627638992437 ) ;
28- expect ( maxDiff ) . toEqual ( 0.0009183359547574563 ) ;
51+ expect ( diff ) . toEqual ( 0.000008817411988770792 ) ;
52+ expect ( maxDiff ) . toEqual ( 0.0009424140621439462 ) ;
2953} ) ;
3054
3155describe ( 'when images are of different width' , ( ) => {
3256 beforeEach ( async ( ) => {
33- image1 = ( await Jimp . read ( 'http://127.0.0.1:5411/alert-before.png' ) ) . bitmap ;
34- image2 = ( await Jimp . read ( 'http://127.0.0.1:5411/alert-after.png' ) ) . bitmap ;
57+ const image1Sharp = sharp (
58+ path . resolve ( __dirname , 'test-images/alert-before.png' ) ,
59+ ) ;
60+ const image2Sharp = sharp (
61+ path . resolve ( __dirname , 'test-images/alert-after.png' ) ,
62+ ) ;
63+
64+ const [ image1Metadata , image2Metadata ] = await Promise . all ( [
65+ image1Sharp . metadata ( ) ,
66+ image2Sharp . metadata ( ) ,
67+ ] ) ;
68+
69+ const [ image1Buffer , image2Buffer ] = await Promise . all ( [
70+ image1Sharp . raw ( ) . toBuffer ( ) ,
71+ image2Sharp . raw ( ) . toBuffer ( ) ,
72+ ] ) ;
73+
74+ image1 = {
75+ data : image1Buffer ,
76+ width : image1Metadata . width ,
77+ height : image1Metadata . height ,
78+ } ;
79+ image2 = {
80+ data : image2Buffer ,
81+ width : image2Metadata . width ,
82+ height : image2Metadata . height ,
83+ } ;
3584 } ) ;
3685
3786 it ( 'has a total diff and a max diff' , async ( ) => {
@@ -43,13 +92,38 @@ describe('when images are of different width', () => {
4392
4493describe ( 'when images are of different height' , ( ) => {
4594 beforeEach ( async ( ) => {
46- image1 = ( await Jimp . read ( 'http://127.0.0.1:5411/button-before.png' ) ) . bitmap ;
47- image2 = ( await Jimp . read ( 'http://127.0.0.1:5411/button-after.png' ) ) . bitmap ;
95+ const image1Sharp = sharp (
96+ path . resolve ( __dirname , 'test-images/button-before.png' ) ,
97+ ) ;
98+ const image2Sharp = sharp (
99+ path . resolve ( __dirname , 'test-images/button-after.png' ) ,
100+ ) ;
101+
102+ const [ image1Metadata , image2Metadata ] = await Promise . all ( [
103+ image1Sharp . metadata ( ) ,
104+ image2Sharp . metadata ( ) ,
105+ ] ) ;
106+
107+ const [ image1Buffer , image2Buffer ] = await Promise . all ( [
108+ image1Sharp . raw ( ) . toBuffer ( ) ,
109+ image2Sharp . raw ( ) . toBuffer ( ) ,
110+ ] ) ;
111+
112+ image1 = {
113+ data : image1Buffer ,
114+ width : image1Metadata . width ,
115+ height : image1Metadata . height ,
116+ } ;
117+ image2 = {
118+ data : image2Buffer ,
119+ width : image2Metadata . width ,
120+ height : image2Metadata . height ,
121+ } ;
48122 } ) ;
49123
50124 it ( 'has a total diff and a max diff' , async ( ) => {
51125 const { diff, maxDiff } = await subject ( ) ;
52- expect ( diff ) . toBeTruthy ( )
126+ expect ( diff ) . toBeTruthy ( ) ;
53127 expect ( maxDiff ) . toBeTruthy ( ) ;
54128 } ) ;
55129} ) ;
0 commit comments