@@ -9,7 +9,7 @@ jest.mock(`async/queue`, () => () => {
9
9
} )
10
10
jest . mock ( `gatsby/dist/redux/actions` , ( ) => {
11
11
return {
12
- boundActionCreators : {
12
+ actions : {
13
13
createJobV2 : jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) ) ,
14
14
} ,
15
15
}
@@ -30,7 +30,7 @@ const {
30
30
getImageSize,
31
31
getImageSizeAsync,
32
32
stats,
33
- setBoundActionCreators ,
33
+ setActions ,
34
34
} = require ( `../` )
35
35
36
36
const {
@@ -73,15 +73,13 @@ describe(`gatsby-plugin-sharp`, () => {
73
73
describe ( `queueImageResizing` , ( ) => {
74
74
; [ `createJob` , `createJobV2` ] . forEach ( api => {
75
75
describe ( `with ${ api } ` , ( ) => {
76
- let boundActionCreators
76
+ let actions
77
77
beforeEach ( ( ) => {
78
- boundActionCreators = { }
78
+ actions = { }
79
79
if ( api === `createJobV2` ) {
80
- boundActionCreators . createJobV2 = jest
81
- . fn ( )
82
- . mockReturnValue ( Promise . resolve ( ) )
80
+ actions . createJobV2 = jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) )
83
81
}
84
- setBoundActionCreators ( boundActionCreators )
82
+ setActions ( actions )
85
83
scheduleJob . mockClear ( )
86
84
} )
87
85
@@ -96,8 +94,8 @@ describe(`gatsby-plugin-sharp`, () => {
96
94
// We expect value to be rounded to 1
97
95
expect ( result . height ) . toBe ( 1 )
98
96
if ( api === `createJobV2` ) {
99
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
100
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
97
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
98
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
101
99
} else {
102
100
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
103
101
expect ( scheduleJob ) . toMatchSnapshot ( )
@@ -126,8 +124,8 @@ describe(`gatsby-plugin-sharp`, () => {
126
124
expect ( testName . match ( / [ ! @ # $ ^ & , " ] / ) ) . not . toBe ( false )
127
125
expect ( queueResultName . match ( / [ ! @ # $ ^ & , " ] / ) ) . not . toBe ( true )
128
126
if ( api === `createJobV2` ) {
129
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
130
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
127
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
128
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
131
129
} else {
132
130
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
133
131
expect ( scheduleJob ) . toMatchSnapshot ( )
@@ -150,61 +148,59 @@ describe(`gatsby-plugin-sharp`, () => {
150
148
151
149
it ( `should return the same result when using createJob as createJobV2` , async ( ) => {
152
150
scheduleJob . mockClear ( )
153
- const boundActionCreators = {
151
+ const actions = {
154
152
createJobV2 : jest . fn ( ( ) => Promise . resolve ( ) ) ,
155
153
}
156
- setBoundActionCreators ( boundActionCreators )
154
+ setActions ( actions )
157
155
const resultV2 = await queueImageResizing ( {
158
156
file : getFileObject ( path . join ( __dirname , `images/144-density.png` ) ) ,
159
157
args : { width : 3 } ,
160
158
} )
161
159
162
- setBoundActionCreators ( { } )
160
+ setActions ( { } )
163
161
const result = await queueImageResizing ( {
164
162
file : getFileObject ( path . join ( __dirname , `images/144-density.png` ) ) ,
165
163
args : { width : 3 } ,
166
164
} )
167
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
165
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
168
166
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
169
167
expect ( result ) . toStrictEqual ( resultV2 )
170
168
} )
171
169
} )
172
170
173
171
describe ( `fluid` , ( ) => {
174
- let boundActionCreators = { }
172
+ let actions = { }
175
173
beforeEach ( ( ) => {
176
- boundActionCreators . createJobV2 = jest
177
- . fn ( )
178
- . mockReturnValue ( Promise . resolve ( ) )
179
- setBoundActionCreators ( boundActionCreators )
174
+ actions . createJobV2 = jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) )
175
+ setActions ( actions )
180
176
scheduleJob . mockClear ( )
181
177
} )
182
178
183
179
it ( `includes responsive image properties, e.g. sizes, srcset, etc.` , async ( ) => {
184
180
const result = await fluid ( { file } )
185
181
186
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
182
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
187
183
expect ( result ) . toMatchSnapshot ( )
188
184
} )
189
185
190
186
it ( `includes responsive image properties, e.g. sizes, srcset, etc. with the createJob api` , async ( ) => {
191
- setBoundActionCreators ( { } )
187
+ setActions ( { } )
192
188
const result = await fluid ( { file } )
193
189
194
- expect ( boundActionCreators . createJobV2 ) . not . toHaveBeenCalled ( )
190
+ expect ( actions . createJobV2 ) . not . toHaveBeenCalled ( )
195
191
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
196
192
expect ( result ) . toMatchSnapshot ( )
197
193
} )
198
194
199
195
it ( `should give the same result with createJob as with createJobV2` , async ( ) => {
200
196
const resultV2 = await fluid ( { file } )
201
197
202
- setBoundActionCreators ( { } )
198
+ setActions ( { } )
203
199
const result = await fluid ( { file } )
204
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
200
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
205
201
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
206
202
expect ( result ) . toStrictEqual ( resultV2 )
207
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
203
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
208
204
} )
209
205
210
206
it ( `adds pathPrefix if defined` , async ( ) => {
@@ -218,7 +214,7 @@ describe(`gatsby-plugin-sharp`, () => {
218
214
219
215
expect ( result . src . indexOf ( pathPrefix ) ) . toBe ( 0 )
220
216
expect ( result . srcSet . indexOf ( pathPrefix ) ) . toBe ( 0 )
221
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
217
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
222
218
} )
223
219
224
220
it ( `keeps original file name` , async ( ) => {
@@ -228,7 +224,7 @@ describe(`gatsby-plugin-sharp`, () => {
228
224
229
225
expect ( path . parse ( result . src ) . name ) . toBe ( file . name )
230
226
expect ( path . parse ( result . srcSet ) . name ) . toBe ( file . name )
231
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
227
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
232
228
} )
233
229
234
230
it ( `does not change the arguments object it is given` , async ( ) => {
@@ -239,7 +235,7 @@ describe(`gatsby-plugin-sharp`, () => {
239
235
} )
240
236
241
237
expect ( args ) . toEqual ( { maxWidth : 400 } )
242
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
238
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
243
239
} )
244
240
245
241
it ( `infers the maxWidth if only maxHeight is given` , async ( ) => {
@@ -250,7 +246,7 @@ describe(`gatsby-plugin-sharp`, () => {
250
246
} )
251
247
252
248
expect ( result . presentationWidth ) . toEqual ( 41 )
253
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
249
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
254
250
} )
255
251
256
252
it ( `calculate height based on width when maxWidth & maxHeight are present` , async ( ) => {
@@ -287,13 +283,13 @@ describe(`gatsby-plugin-sharp`, () => {
287
283
)
288
284
289
285
for ( const testCase of testsCases ) {
290
- boundActionCreators . createJobV2 . mockClear ( )
286
+ actions . createJobV2 . mockClear ( )
291
287
const result = await fluid ( {
292
288
file : fileObject ,
293
289
args : testCase . args ,
294
290
} )
295
291
296
- expect ( boundActionCreators . createJobV2 . mock . calls ) . toMatchSnapshot ( )
292
+ expect ( actions . createJobV2 . mock . calls ) . toMatchSnapshot ( )
297
293
expect ( result . presentationWidth ) . toEqual ( testCase . result [ 0 ] )
298
294
expect ( result . presentationHeight ) . toEqual ( testCase . result [ 1 ] )
299
295
}
@@ -307,7 +303,7 @@ describe(`gatsby-plugin-sharp`, () => {
307
303
} )
308
304
309
305
await expect ( result ) . rejects . toThrow ( )
310
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
306
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
311
307
} )
312
308
313
309
it ( `accepts srcSet breakpoints` , async ( ) => {
@@ -327,7 +323,7 @@ describe(`gatsby-plugin-sharp`, () => {
327
323
const actual = findAllBreakpoints ( result . srcSet )
328
324
// should contain all requested sizes as well as the original size
329
325
expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
330
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
326
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
331
327
} )
332
328
333
329
it ( `should throw on srcSet breakpoints less than 1` , async ( ) => {
@@ -339,7 +335,7 @@ describe(`gatsby-plugin-sharp`, () => {
339
335
} )
340
336
341
337
await expect ( result ) . rejects . toThrow ( )
342
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
338
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
343
339
} )
344
340
345
341
it ( `ensure maxWidth is in srcSet breakpoints` , async ( ) => {
@@ -355,7 +351,7 @@ describe(`gatsby-plugin-sharp`, () => {
355
351
} )
356
352
357
353
expect ( result . srcSet ) . toEqual ( expect . stringContaining ( `${ maxWidth } w` ) )
358
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
354
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
359
355
} )
360
356
361
357
it ( `reject any breakpoints larger than the original width` , async ( ) => {
@@ -390,7 +386,7 @@ describe(`gatsby-plugin-sharp`, () => {
390
386
expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
391
387
// should contain no other sizes
392
388
expect ( actual . length ) . toEqual ( expected . length )
393
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
389
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
394
390
} )
395
391
396
392
it ( `prevents duplicate breakpoints` , async ( ) => {
@@ -411,34 +407,32 @@ describe(`gatsby-plugin-sharp`, () => {
411
407
const actual = findAllBreakpoints ( result . srcSet )
412
408
expect ( actual ) . toEqual ( expect . arrayContaining ( expected ) )
413
409
expect ( actual . length ) . toEqual ( expected . length )
414
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
410
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
415
411
} )
416
412
} )
417
413
418
414
describe ( `fixed` , ( ) => {
419
- let boundActionCreators = { }
415
+ let actions = { }
420
416
beforeEach ( ( ) => {
421
- boundActionCreators . createJobV2 = jest
422
- . fn ( )
423
- . mockReturnValue ( Promise . resolve ( ) )
424
- setBoundActionCreators ( boundActionCreators )
417
+ actions . createJobV2 = jest . fn ( ) . mockReturnValue ( Promise . resolve ( ) )
418
+ setActions ( actions )
425
419
scheduleJob . mockClear ( )
426
420
console . warn = jest . fn ( )
427
421
} )
428
422
429
423
it ( `should give the same result with createJob as with createJobV2` , async ( ) => {
430
- const boundActionCreators = {
424
+ const actions = {
431
425
createJobV2 : jest . fn ( ( ) => Promise . resolve ( ) ) ,
432
426
}
433
- setBoundActionCreators ( boundActionCreators )
427
+ setActions ( actions )
434
428
const resultV2 = await fixed ( { file, args : { width : 1 } } )
435
429
436
- setBoundActionCreators ( { } )
430
+ setActions ( { } )
437
431
const result = await fixed ( { file, args : { width : 1 } } )
438
- expect ( boundActionCreators . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
432
+ expect ( actions . createJobV2 ) . toHaveBeenCalledTimes ( 1 )
439
433
expect ( scheduleJob ) . toHaveBeenCalledTimes ( 1 )
440
434
expect ( result ) . toStrictEqual ( resultV2 )
441
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
435
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
442
436
} )
443
437
444
438
it ( `does not warn when the requested width is equal to the image width` , async ( ) => {
@@ -451,7 +445,7 @@ describe(`gatsby-plugin-sharp`, () => {
451
445
452
446
expect ( result . width ) . toEqual ( 1 )
453
447
expect ( console . warn ) . toHaveBeenCalledTimes ( 0 )
454
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
448
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
455
449
} )
456
450
457
451
it ( `warns when the requested width is greater than the image width` , async ( ) => {
@@ -465,7 +459,7 @@ describe(`gatsby-plugin-sharp`, () => {
465
459
466
460
expect ( result . width ) . toEqual ( width )
467
461
expect ( console . warn ) . toHaveBeenCalledTimes ( 1 )
468
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
462
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
469
463
} )
470
464
471
465
it ( `correctly infers the width when only the height is given` , async ( ) => {
@@ -477,7 +471,7 @@ describe(`gatsby-plugin-sharp`, () => {
477
471
} )
478
472
479
473
expect ( result . width ) . toEqual ( 21 )
480
- expect ( boundActionCreators . createJobV2 ) . toMatchSnapshot ( )
474
+ expect ( actions . createJobV2 ) . toMatchSnapshot ( )
481
475
} )
482
476
} )
483
477
0 commit comments