@@ -11,10 +11,12 @@ const FIXTURES_DIR = `${__dirname}/fixtures`
11
11
12
12
const utils = {
13
13
run : {
14
- command : jest . fn ( ) ,
14
+ command ( ) { } ,
15
15
} ,
16
16
build : {
17
- failBuild : jest . fn ( ) ,
17
+ failBuild ( message ) {
18
+ throw new Error ( message )
19
+ } ,
18
20
} ,
19
21
}
20
22
@@ -41,8 +43,6 @@ beforeEach(async () => {
41
43
} )
42
44
43
45
afterEach ( async ( ) => {
44
- utils . build . failBuild . mockReset ( )
45
- utils . run . command . mockReset ( )
46
46
jest . clearAllMocks ( )
47
47
jest . resetAllMocks ( )
48
48
@@ -58,53 +58,47 @@ const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
58
58
59
59
describe ( 'preBuild()' , ( ) => {
60
60
test ( 'fail build if the app has static html export in npm script' , async ( ) => {
61
- await plugin . onPreBuild ( {
62
- netlifyConfig : { } ,
63
- packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
64
- utils,
65
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
66
- } )
67
-
68
- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
69
- '** Static HTML export next.js projects do not require this plugin **' ,
70
- )
61
+ await expect (
62
+ plugin . onPreBuild ( {
63
+ netlifyConfig : { } ,
64
+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
65
+ utils,
66
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
67
+ } ) ,
68
+ ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
71
69
} )
72
70
73
71
test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
74
- const netlifyConfig = { build : { command : 'next build && next export' } }
75
-
76
- await plugin . onPreBuild ( {
77
- netlifyConfig,
78
- packageJson : DUMMY_PACKAGE_JSON ,
79
- utils,
80
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
81
- } )
82
-
83
- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
84
- '** Static HTML export next.js projects do not require this plugin **' ,
85
- )
72
+ await expect (
73
+ plugin . onPreBuild ( {
74
+ netlifyConfig : { build : { command : 'next build && next export' } } ,
75
+ packageJson : DUMMY_PACKAGE_JSON ,
76
+ utils,
77
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
78
+ } ) ,
79
+ ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
86
80
} )
87
81
88
82
test ( 'fail build if the app has no package.json' , async ( ) => {
89
- await plugin . onPreBuild ( {
90
- netlifyConfig : { } ,
91
- packageJson : { } ,
92
- utils ,
93
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
94
- } )
95
-
96
- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual ( `Could not find a package.json for this project` )
83
+ await expect (
84
+ plugin . onPreBuild ( {
85
+ netlifyConfig : { } ,
86
+ packageJson : { } ,
87
+ utils ,
88
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
89
+ } ) ,
90
+ ) . rejects . toThrow ( `Could not find a package.json for this project` )
97
91
} )
98
92
99
93
test ( 'fail build if the app has no functions directory defined' , async ( ) => {
100
- await plugin . onPreBuild ( {
101
- netlifyConfig : { } ,
102
- packageJson : DUMMY_PACKAGE_JSON ,
103
- utils ,
104
- constants : { } ,
105
- } )
106
-
107
- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
94
+ await expect (
95
+ plugin . onPreBuild ( {
96
+ netlifyConfig : { } ,
97
+ packageJson : DUMMY_PACKAGE_JSON ,
98
+ utils ,
99
+ constants : { } ,
100
+ } ) ,
101
+ ) . rejects . toThrow (
108
102
`You must designate a functions directory named "out_functions" in your netlify.toml or in your app's build settings on Netlify. See docs for more info: https://docs.netlify.com/functions/configure-and-deploy/#configure-the-functions-folder` ,
109
103
)
110
104
} )
@@ -122,18 +116,15 @@ describe('preBuild()', () => {
122
116
123
117
test ( `fail build if the app's next config has an invalid target` , async ( ) => {
124
118
const { restoreCwd } = useFixture ( 'invalid_next_config' )
125
- await plugin . onPreBuild ( {
126
- netlifyConfig : { } ,
127
- packageJson : DUMMY_PACKAGE_JSON ,
128
- utils,
129
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
130
- } )
119
+ await expect (
120
+ plugin . onPreBuild ( {
121
+ netlifyConfig : { } ,
122
+ packageJson : DUMMY_PACKAGE_JSON ,
123
+ utils,
124
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
125
+ } ) ,
126
+ ) . rejects . toThrow ( `next.config.js must be one of: serverless, experimental-serverless-trace` )
131
127
restoreCwd ( )
132
-
133
- const acceptableTargets = [ 'serverless' , 'experimental-serverless-trace' ]
134
- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
135
- `next.config.js must be one of: ${ acceptableTargets . join ( ', ' ) } ` ,
136
- )
137
128
} )
138
129
} )
139
130
0 commit comments