Skip to content

Commit 95681a1

Browse files
committed
chore: added unit tests for size warning
1 parent b651e67 commit 95681a1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/helpers/verification.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ describe('checkNextSiteHasBuilt', () => {
8989

9090
describe('checkZipSize', () => {
9191
let consoleSpy
92+
const { existsSync, promises } = require('fs')
9293

9394
beforeEach(() => {
9495
consoleSpy = jest.spyOn(global.console, 'warn')
96+
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK = 'false'
9597
})
9698

9799
afterEach(() => {
@@ -103,6 +105,28 @@ describe('checkZipSize', () => {
103105
await checkZipSize(chance.string())
104106
expect(consoleSpy).toHaveBeenCalledWith('Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment variable. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.')
105107
})
108+
109+
it('does not emit a warning if the file size is below the warning size', async () => {
110+
existsSync.mockReturnValue(true)
111+
jest.spyOn(promises, 'stat').mockResolvedValue({ size: (1024 * 1024 * 20) })
112+
113+
await checkZipSize('some-file.zip')
114+
115+
expect(consoleSpy).not.toHaveBeenCalled()
116+
})
117+
118+
it('emits a warning if the file size is above the warning size', async () => {
119+
existsSync.mockReturnValue(true)
120+
jest.spyOn(promises, 'stat').mockResolvedValue({ size: (1024 * 1024 * 200) })
121+
122+
await checkZipSize('some-file.zip')
123+
124+
expect(consoleSpy).toHaveBeenCalledWith(
125+
expect.stringContaining(
126+
'The function zip some-file.zip size is 200 MB, which is larger than the recommended maximum size of 250 MB.'
127+
)
128+
)
129+
})
106130
})
107131

108132
describe("getProblematicUserRewrites", () => {

0 commit comments

Comments
 (0)