Skip to content

Commit d96c923

Browse files
committed
fix: update tests
1 parent 2afd1cd commit d96c923

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ module.exports = {
2525
'unicorn/filename-case': 0,
2626
'unicorn/no-array-push-push': 0,
2727
},
28+
env: {
29+
'jest/globals': true,
30+
},
2831
overrides: [...overrides],
2932
}

test/index.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,16 @@ describe('preBuild()', () => {
235235
test('restores cache with right paths', async () => {
236236
await useFixture('dist_dir_next_config')
237237

238-
let distPath
239-
const utils_ = {
240-
...utils,
241-
cache: {
242-
restore: (x) => (distPath = x),
243-
},
244-
}
245-
const spy = jest.spyOn(utils_.cache, 'restore')
238+
const restore = jest.fn()
246239

247240
await plugin.onPreBuild({
248241
netlifyConfig,
249242
packageJson: DUMMY_PACKAGE_JSON,
250-
utils: utils_,
243+
utils: { ...utils, cache: { restore } },
251244
constants: { FUNCTIONS_SRC: 'out_functions' },
252245
})
253246

254-
expect(spy).toHaveBeenCalled()
255-
expect(path.normalize(distPath)).toBe(path.normalize('build/cache'))
247+
expect(restore).toHaveBeenCalledWith(path.resolve('build/cache'))
256248
})
257249
})
258250

@@ -316,29 +308,18 @@ describe('onPostBuild', () => {
316308
test('saves cache with right paths', async () => {
317309
await useFixture('dist_dir_next_config')
318310

319-
let distPath
320-
let manifestPath
321-
const utils_ = {
322-
...utils,
323-
cache: {
324-
save: (x, y) => {
325-
distPath = x
326-
manifestPath = y
327-
},
328-
},
329-
}
330-
const spy = jest.spyOn(utils_.cache, 'save')
311+
const save = jest.fn()
331312

332313
await plugin.onPostBuild({
333314
netlifyConfig,
334315
packageJson: DUMMY_PACKAGE_JSON,
335-
utils: utils_,
316+
utils: { ...utils, cache: { save } },
336317
constants: { FUNCTIONS_SRC: 'out_functions' },
337318
})
338319

339-
expect(spy).toHaveBeenCalled()
340-
expect(path.normalize(distPath)).toBe(path.normalize('build/cache'))
341-
expect(path.normalize(manifestPath.digests[0])).toBe(path.normalize('build/build-manifest.json'))
320+
expect(save).toHaveBeenCalledWith(path.resolve('build/cache'), {
321+
digests: [path.resolve('build/build-manifest.json')],
322+
})
342323
})
343324
})
344325

0 commit comments

Comments
 (0)