Skip to content

Commit b1f8663

Browse files
LekoArtsgatsbybot
and
gatsbybot
authored
feat(gatsby): Remove boundActionCreators (#29129)
Co-authored-by: gatsbybot <[email protected]>
1 parent bde7394 commit b1f8663

File tree

28 files changed

+195
-201
lines changed

28 files changed

+195
-201
lines changed

packages/gatsby-plugin-sharp/src/__tests__/index.js

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jest.mock(`async/queue`, () => () => {
99
})
1010
jest.mock(`gatsby/dist/redux/actions`, () => {
1111
return {
12-
boundActionCreators: {
12+
actions: {
1313
createJobV2: jest.fn().mockReturnValue(Promise.resolve()),
1414
},
1515
}
@@ -30,7 +30,7 @@ const {
3030
getImageSize,
3131
getImageSizeAsync,
3232
stats,
33-
setBoundActionCreators,
33+
setActions,
3434
} = require(`../`)
3535

3636
const {
@@ -73,15 +73,13 @@ describe(`gatsby-plugin-sharp`, () => {
7373
describe(`queueImageResizing`, () => {
7474
;[`createJob`, `createJobV2`].forEach(api => {
7575
describe(`with ${api}`, () => {
76-
let boundActionCreators
76+
let actions
7777
beforeEach(() => {
78-
boundActionCreators = {}
78+
actions = {}
7979
if (api === `createJobV2`) {
80-
boundActionCreators.createJobV2 = jest
81-
.fn()
82-
.mockReturnValue(Promise.resolve())
80+
actions.createJobV2 = jest.fn().mockReturnValue(Promise.resolve())
8381
}
84-
setBoundActionCreators(boundActionCreators)
82+
setActions(actions)
8583
scheduleJob.mockClear()
8684
})
8785

@@ -96,8 +94,8 @@ describe(`gatsby-plugin-sharp`, () => {
9694
// We expect value to be rounded to 1
9795
expect(result.height).toBe(1)
9896
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()
10199
} else {
102100
expect(scheduleJob).toHaveBeenCalledTimes(1)
103101
expect(scheduleJob).toMatchSnapshot()
@@ -126,8 +124,8 @@ describe(`gatsby-plugin-sharp`, () => {
126124
expect(testName.match(/[!@#$^&," ]/)).not.toBe(false)
127125
expect(queueResultName.match(/[!@#$^&," ]/)).not.toBe(true)
128126
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()
131129
} else {
132130
expect(scheduleJob).toHaveBeenCalledTimes(1)
133131
expect(scheduleJob).toMatchSnapshot()
@@ -150,61 +148,59 @@ describe(`gatsby-plugin-sharp`, () => {
150148

151149
it(`should return the same result when using createJob as createJobV2`, async () => {
152150
scheduleJob.mockClear()
153-
const boundActionCreators = {
151+
const actions = {
154152
createJobV2: jest.fn(() => Promise.resolve()),
155153
}
156-
setBoundActionCreators(boundActionCreators)
154+
setActions(actions)
157155
const resultV2 = await queueImageResizing({
158156
file: getFileObject(path.join(__dirname, `images/144-density.png`)),
159157
args: { width: 3 },
160158
})
161159

162-
setBoundActionCreators({})
160+
setActions({})
163161
const result = await queueImageResizing({
164162
file: getFileObject(path.join(__dirname, `images/144-density.png`)),
165163
args: { width: 3 },
166164
})
167-
expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1)
165+
expect(actions.createJobV2).toHaveBeenCalledTimes(1)
168166
expect(scheduleJob).toHaveBeenCalledTimes(1)
169167
expect(result).toStrictEqual(resultV2)
170168
})
171169
})
172170

173171
describe(`fluid`, () => {
174-
let boundActionCreators = {}
172+
let actions = {}
175173
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)
180176
scheduleJob.mockClear()
181177
})
182178

183179
it(`includes responsive image properties, e.g. sizes, srcset, etc.`, async () => {
184180
const result = await fluid({ file })
185181

186-
expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1)
182+
expect(actions.createJobV2).toHaveBeenCalledTimes(1)
187183
expect(result).toMatchSnapshot()
188184
})
189185

190186
it(`includes responsive image properties, e.g. sizes, srcset, etc. with the createJob api`, async () => {
191-
setBoundActionCreators({})
187+
setActions({})
192188
const result = await fluid({ file })
193189

194-
expect(boundActionCreators.createJobV2).not.toHaveBeenCalled()
190+
expect(actions.createJobV2).not.toHaveBeenCalled()
195191
expect(scheduleJob).toHaveBeenCalledTimes(1)
196192
expect(result).toMatchSnapshot()
197193
})
198194

199195
it(`should give the same result with createJob as with createJobV2`, async () => {
200196
const resultV2 = await fluid({ file })
201197

202-
setBoundActionCreators({})
198+
setActions({})
203199
const result = await fluid({ file })
204-
expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1)
200+
expect(actions.createJobV2).toHaveBeenCalledTimes(1)
205201
expect(scheduleJob).toHaveBeenCalledTimes(1)
206202
expect(result).toStrictEqual(resultV2)
207-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
203+
expect(actions.createJobV2).toMatchSnapshot()
208204
})
209205

210206
it(`adds pathPrefix if defined`, async () => {
@@ -218,7 +214,7 @@ describe(`gatsby-plugin-sharp`, () => {
218214

219215
expect(result.src.indexOf(pathPrefix)).toBe(0)
220216
expect(result.srcSet.indexOf(pathPrefix)).toBe(0)
221-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
217+
expect(actions.createJobV2).toMatchSnapshot()
222218
})
223219

224220
it(`keeps original file name`, async () => {
@@ -228,7 +224,7 @@ describe(`gatsby-plugin-sharp`, () => {
228224

229225
expect(path.parse(result.src).name).toBe(file.name)
230226
expect(path.parse(result.srcSet).name).toBe(file.name)
231-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
227+
expect(actions.createJobV2).toMatchSnapshot()
232228
})
233229

234230
it(`does not change the arguments object it is given`, async () => {
@@ -239,7 +235,7 @@ describe(`gatsby-plugin-sharp`, () => {
239235
})
240236

241237
expect(args).toEqual({ maxWidth: 400 })
242-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
238+
expect(actions.createJobV2).toMatchSnapshot()
243239
})
244240

245241
it(`infers the maxWidth if only maxHeight is given`, async () => {
@@ -250,7 +246,7 @@ describe(`gatsby-plugin-sharp`, () => {
250246
})
251247

252248
expect(result.presentationWidth).toEqual(41)
253-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
249+
expect(actions.createJobV2).toMatchSnapshot()
254250
})
255251

256252
it(`calculate height based on width when maxWidth & maxHeight are present`, async () => {
@@ -287,13 +283,13 @@ describe(`gatsby-plugin-sharp`, () => {
287283
)
288284

289285
for (const testCase of testsCases) {
290-
boundActionCreators.createJobV2.mockClear()
286+
actions.createJobV2.mockClear()
291287
const result = await fluid({
292288
file: fileObject,
293289
args: testCase.args,
294290
})
295291

296-
expect(boundActionCreators.createJobV2.mock.calls).toMatchSnapshot()
292+
expect(actions.createJobV2.mock.calls).toMatchSnapshot()
297293
expect(result.presentationWidth).toEqual(testCase.result[0])
298294
expect(result.presentationHeight).toEqual(testCase.result[1])
299295
}
@@ -307,7 +303,7 @@ describe(`gatsby-plugin-sharp`, () => {
307303
})
308304

309305
await expect(result).rejects.toThrow()
310-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
306+
expect(actions.createJobV2).toMatchSnapshot()
311307
})
312308

313309
it(`accepts srcSet breakpoints`, async () => {
@@ -327,7 +323,7 @@ describe(`gatsby-plugin-sharp`, () => {
327323
const actual = findAllBreakpoints(result.srcSet)
328324
// should contain all requested sizes as well as the original size
329325
expect(actual).toEqual(expect.arrayContaining(expected))
330-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
326+
expect(actions.createJobV2).toMatchSnapshot()
331327
})
332328

333329
it(`should throw on srcSet breakpoints less than 1`, async () => {
@@ -339,7 +335,7 @@ describe(`gatsby-plugin-sharp`, () => {
339335
})
340336

341337
await expect(result).rejects.toThrow()
342-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
338+
expect(actions.createJobV2).toMatchSnapshot()
343339
})
344340

345341
it(`ensure maxWidth is in srcSet breakpoints`, async () => {
@@ -355,7 +351,7 @@ describe(`gatsby-plugin-sharp`, () => {
355351
})
356352

357353
expect(result.srcSet).toEqual(expect.stringContaining(`${maxWidth}w`))
358-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
354+
expect(actions.createJobV2).toMatchSnapshot()
359355
})
360356

361357
it(`reject any breakpoints larger than the original width`, async () => {
@@ -390,7 +386,7 @@ describe(`gatsby-plugin-sharp`, () => {
390386
expect(actual).toEqual(expect.arrayContaining(expected))
391387
// should contain no other sizes
392388
expect(actual.length).toEqual(expected.length)
393-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
389+
expect(actions.createJobV2).toMatchSnapshot()
394390
})
395391

396392
it(`prevents duplicate breakpoints`, async () => {
@@ -411,34 +407,32 @@ describe(`gatsby-plugin-sharp`, () => {
411407
const actual = findAllBreakpoints(result.srcSet)
412408
expect(actual).toEqual(expect.arrayContaining(expected))
413409
expect(actual.length).toEqual(expected.length)
414-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
410+
expect(actions.createJobV2).toMatchSnapshot()
415411
})
416412
})
417413

418414
describe(`fixed`, () => {
419-
let boundActionCreators = {}
415+
let actions = {}
420416
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)
425419
scheduleJob.mockClear()
426420
console.warn = jest.fn()
427421
})
428422

429423
it(`should give the same result with createJob as with createJobV2`, async () => {
430-
const boundActionCreators = {
424+
const actions = {
431425
createJobV2: jest.fn(() => Promise.resolve()),
432426
}
433-
setBoundActionCreators(boundActionCreators)
427+
setActions(actions)
434428
const resultV2 = await fixed({ file, args: { width: 1 } })
435429

436-
setBoundActionCreators({})
430+
setActions({})
437431
const result = await fixed({ file, args: { width: 1 } })
438-
expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1)
432+
expect(actions.createJobV2).toHaveBeenCalledTimes(1)
439433
expect(scheduleJob).toHaveBeenCalledTimes(1)
440434
expect(result).toStrictEqual(resultV2)
441-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
435+
expect(actions.createJobV2).toMatchSnapshot()
442436
})
443437

444438
it(`does not warn when the requested width is equal to the image width`, async () => {
@@ -451,7 +445,7 @@ describe(`gatsby-plugin-sharp`, () => {
451445

452446
expect(result.width).toEqual(1)
453447
expect(console.warn).toHaveBeenCalledTimes(0)
454-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
448+
expect(actions.createJobV2).toMatchSnapshot()
455449
})
456450

457451
it(`warns when the requested width is greater than the image width`, async () => {
@@ -465,7 +459,7 @@ describe(`gatsby-plugin-sharp`, () => {
465459

466460
expect(result.width).toEqual(width)
467461
expect(console.warn).toHaveBeenCalledTimes(1)
468-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
462+
expect(actions.createJobV2).toMatchSnapshot()
469463
})
470464

471465
it(`correctly infers the width when only the height is given`, async () => {
@@ -477,7 +471,7 @@ describe(`gatsby-plugin-sharp`, () => {
477471
})
478472

479473
expect(result.width).toEqual(21)
480-
expect(boundActionCreators.createJobV2).toMatchSnapshot()
474+
expect(actions.createJobV2).toMatchSnapshot()
481475
})
482476
})
483477

packages/gatsby-plugin-sharp/src/__tests__/scheduler.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const fs = require(`fs-extra`)
1010
const workerMock = require(`../gatsby-worker`).IMAGE_PROCESSING
1111

1212
describe(`scheduler`, () => {
13-
let boundActionCreators = {}
13+
let actions = {}
1414
let scheduler
1515
beforeEach(() => {
1616
workerMock.mockReset()
17-
boundActionCreators = {
17+
actions = {
1818
createJob: jest.fn(),
1919
endJob: jest.fn(),
2020
}
@@ -43,7 +43,7 @@ describe(`scheduler`, () => {
4343
pluginOptions: {},
4444
},
4545
}
46-
await scheduleJob(job, boundActionCreators)
46+
await scheduleJob(job, actions)
4747

4848
expect(workerMock).toHaveBeenCalledWith(
4949
expect.objectContaining({
@@ -79,7 +79,7 @@ describe(`scheduler`, () => {
7979
pluginOptions: {},
8080
},
8181
},
82-
boundActionCreators
82+
actions
8383
)
8484
} catch (err) {
8585
expect(err).toEqual(`failed transform`)
@@ -104,7 +104,7 @@ describe(`scheduler`, () => {
104104
pluginOptions: {},
105105
},
106106
}
107-
await scheduleJob(job, boundActionCreators)
107+
await scheduleJob(job, actions)
108108

109109
expect(workerMock).not.toHaveBeenCalled()
110110
fs.existsSync = orignalSync
@@ -126,8 +126,8 @@ describe(`scheduler`, () => {
126126
pluginOptions: {},
127127
},
128128
}
129-
const jobPromise = scheduleJob(job, boundActionCreators)
130-
const job2Promise = scheduleJob(job, boundActionCreators)
129+
const jobPromise = scheduleJob(job, actions)
130+
const job2Promise = scheduleJob(job, actions)
131131
expect(jobPromise).toStrictEqual(job2Promise)
132132

133133
await Promise.all([jobPromise, job2Promise])
@@ -165,7 +165,7 @@ describe(`scheduler`, () => {
165165
},
166166
}
167167

168-
await scheduleJob(job, boundActionCreators)
168+
await scheduleJob(job, actions)
169169

170170
expect(got.post).toHaveBeenCalledWith(
171171
process.env.GATSBY_CLOUD_IMAGE_SERVICE_URL,

packages/gatsby-plugin-sharp/src/gatsby-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {
2-
setBoundActionCreators,
2+
setActions,
33
// queue: jobQueue,
44
// reportError,
55
_unstable_createJob,
@@ -123,7 +123,7 @@ exports.onPreBootstrap = async (
123123
{ actions, emitter, reporter, cache, store },
124124
pluginOptions
125125
) => {
126-
setBoundActionCreators(actions)
126+
setActions(actions)
127127
setPluginOptions(pluginOptions)
128128

129129
// below is a hack / hot fix for confusing progress bar behaviour

0 commit comments

Comments
 (0)