-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathverification.spec.ts
102 lines (79 loc) · 4.1 KB
/
verification.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import Chance from 'chance'
import { checkNextSiteHasBuilt, checkZipSize } from '../../packages/runtime/src/helpers/verification'
import { outdent } from 'outdent'
import type { NetlifyPluginUtils } from '@netlify/build'
type FailBuild = NetlifyPluginUtils['build']['failBuild']
const chance = new Chance()
jest.mock('fs', () => {
return {
existsSync: jest.fn(),
}
})
describe('checkNextSiteHasBuilt', () => {
let failBuildMock
const { existsSync } = require('fs')
beforeEach(() => {
failBuildMock = jest.fn() as unknown as FailBuild
})
afterEach(() => {
jest.clearAllMocks()
jest.resetAllMocks()
})
it('returns error message about incorrectly publishing the ".next" directory when "next export" was run', () => {
existsSync.mockReturnValue(true)
const expectedFailureMessage = outdent`
Detected that "next export" was run, but site is incorrectly publishing the ".next" directory.
The publish directory should be set to "out", and you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
`
checkNextSiteHasBuilt({ publish: '.next', failBuild: failBuildMock })
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
})
it('returns error message prompt to change publish directory to ".next"', () => {
// False for not initially finding the specified 'publish' directory,
// True for successfully finding a '.next' directory with a production build
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true)
const expectedFailureMessage = outdent`
The directory "someCustomDir" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
However, a '.next' directory was found with a production build.
Consider changing your 'publish' directory to '.next'
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
`
checkNextSiteHasBuilt({ publish: 'someCustomDir', failBuild: failBuildMock })
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
})
it('returns error message prompt when publish directory is set to "out"', () => {
existsSync.mockReturnValue(false)
const expectedFailureMessage = outdent`
The directory "out" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
Your publish directory is set to "out", but in most cases it should be ".next".
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
`
checkNextSiteHasBuilt({ publish: 'out', failBuild: failBuildMock })
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
})
it('returns default error message when production build was not found', () => {
existsSync.mockReturnValue(false)
const expectedFailureMessage = outdent`
The directory ".next" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
`
checkNextSiteHasBuilt({ publish: '.next', failBuild: failBuildMock })
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage)
})
})
describe('checkZipSize', () => {
let consoleSpy
beforeEach(() => {
consoleSpy = jest.spyOn(global.console, 'warn')
})
afterEach(() => {
jest.restoreAllMocks()
delete process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK
})
it('emits a warning that DISABLE_BUNDLE_ZIP_SIZE_CHECK was enabled', async () => {
process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK = 'false'
await checkZipSize(chance.string())
expect(consoleSpy).toHaveBeenCalledWith('Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.')
})
})