@@ -12,6 +12,8 @@ const getNextConfig = require('../src/helpers/getNextConfig')
12
12
// const resolveNextModule = require('../src/helpers/resolveNextModule')
13
13
const usesBuildCommand = require ( '../src/helpers/usesBuildCommand' )
14
14
15
+ const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME } = require ( '../src/constants' )
16
+
15
17
const FIXTURES_DIR = `${ __dirname } /fixtures`
16
18
const SAMPLE_PROJECT_DIR = `${ __dirname } /../demo`
17
19
@@ -36,6 +38,9 @@ const changeCwd = function (cwd) {
36
38
}
37
39
}
38
40
41
+ const prebuildHasRun = ( netlifyConfig ) =>
42
+ netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . included_files . some ( ( file ) => file . includes ( 'BUILD_ID' ) )
43
+
39
44
// Move .next from sample project to current directory
40
45
const moveNextDist = async function ( ) {
41
46
await cpy ( '.next/**' , process . cwd ( ) , { cwd : SAMPLE_PROJECT_DIR , parents : true , overwrite : false , dot : true } )
@@ -74,6 +79,8 @@ beforeEach(async () => {
74
79
Object . assign ( this , { cleanup, restoreCwd } )
75
80
netlifyConfig . build . publish = path . join ( process . cwd ( ) , '.next' )
76
81
netlifyConfig . redirects = [ ]
82
+ netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] && ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] . included_files = [ ] )
83
+ netlifyConfig . functions [ ODB_FUNCTION_NAME ] && ( netlifyConfig . functions [ ODB_FUNCTION_NAME ] . included_files = [ ] )
77
84
await useFixture ( 'serverless_next_config' )
78
85
} )
79
86
@@ -106,7 +113,7 @@ describe('preBuild()', () => {
106
113
utils,
107
114
constants : { IS_LOCAL : true , NETLIFY_BUILD_VERSION : '15.12.0' } ,
108
115
} )
109
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBe ( 'server' )
116
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeTruthy ( )
110
117
} )
111
118
112
119
test ( 'do nothing if the app has no build command' , async ( ) => {
@@ -117,7 +124,7 @@ describe('preBuild()', () => {
117
124
constants : { FUNCTIONS_SRC : 'out_functions' } ,
118
125
} )
119
126
120
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBeUndefined ( )
127
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeFalsy ( )
121
128
} )
122
129
123
130
test ( 'do nothing if the app has static html export in npm script' , async ( ) => {
@@ -128,7 +135,7 @@ describe('preBuild()', () => {
128
135
constants : { FUNCTIONS_SRC : 'out_functions' } ,
129
136
} )
130
137
131
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBeUndefined ( )
138
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeFalsy ( )
132
139
} )
133
140
134
141
test ( 'run plugin if `NEXT_PLUGIN_FORCE_RUN` is set to true, even if next export is in script' , async ( ) => {
@@ -139,7 +146,7 @@ describe('preBuild()', () => {
139
146
utils,
140
147
constants : { } ,
141
148
} )
142
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBe ( 'server' )
149
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeTruthy ( )
143
150
process . env . NEXT_PLUGIN_FORCE_RUN = undefined
144
151
} )
145
152
@@ -151,7 +158,7 @@ describe('preBuild()', () => {
151
158
utils,
152
159
constants : { } ,
153
160
} )
154
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBe ( 'server' )
161
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeTruthy ( )
155
162
process . env . NEXT_PLUGIN_FORCE_RUN = undefined
156
163
} )
157
164
@@ -163,7 +170,7 @@ describe('preBuild()', () => {
163
170
utils,
164
171
constants : { } ,
165
172
} )
166
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBeUndefined ( )
173
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeFalsy ( )
167
174
process . env . NEXT_PLUGIN_FORCE_RUN = undefined
168
175
} )
169
176
@@ -174,7 +181,7 @@ describe('preBuild()', () => {
174
181
utils,
175
182
constants : { } ,
176
183
} )
177
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBeUndefined ( )
184
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeFalsy ( )
178
185
} )
179
186
180
187
test ( 'do nothing if build command calls a script that includes "build-storybook"' , async ( ) => {
@@ -184,7 +191,7 @@ describe('preBuild()', () => {
184
191
utils,
185
192
constants : { } ,
186
193
} )
187
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBeUndefined ( )
194
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeFalsy ( )
188
195
} )
189
196
190
197
test ( 'run plugin if app has build-storybook in an unused script' , async ( ) => {
@@ -194,7 +201,7 @@ describe('preBuild()', () => {
194
201
utils,
195
202
constants : { } ,
196
203
} )
197
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBe ( 'server' )
204
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeTruthy ( )
198
205
} )
199
206
200
207
test ( 'fail build if the app has no package.json' , async ( ) => {
@@ -229,7 +236,7 @@ describe('preBuild()', () => {
229
236
utils,
230
237
} )
231
238
232
- expect ( process . env . NEXT_PRIVATE_TARGET ) . toBe ( 'server' )
239
+ expect ( prebuildHasRun ( netlifyConfig ) ) . toBeTruthy ( )
233
240
} )
234
241
235
242
test ( 'fail build if wrong custom publish dir' , async ( ) => {
@@ -241,8 +248,10 @@ describe('preBuild()', () => {
241
248
packageJson,
242
249
constants : { } ,
243
250
utils,
244
- } )
245
- ) . rejects . toThrow ( `You set your publish directory to "${ wrongPublishDir } ". Your publish directory should be set to your distDir (defaults to .next or is configured in your next.config.js). If your site is rooted in a subdirectory, your publish directory should be {yourSiteRoot}/{distDir}.` )
251
+ } ) ,
252
+ ) . rejects . toThrow (
253
+ `You set your publish directory to "${ wrongPublishDir } ". Your publish directory should be set to your distDir (defaults to .next or is configured in your next.config.js). If your site is rooted in a subdirectory, your publish directory should be {yourSiteRoot}/{distDir}.` ,
254
+ )
246
255
} )
247
256
248
257
test ( 'fail build if no publish dir' , async ( ) => {
@@ -252,8 +261,10 @@ describe('preBuild()', () => {
252
261
packageJson,
253
262
constants : { } ,
254
263
utils,
255
- } )
256
- ) . rejects . toThrow ( 'You set your publish directory to "null". Your publish directory should be set to your distDir (defaults to .next or is configured in your next.config.js). If your site is rooted in a subdirectory, your publish directory should be {yourSiteRoot}/{distDir}.' )
264
+ } ) ,
265
+ ) . rejects . toThrow (
266
+ 'You set your publish directory to "null". Your publish directory should be set to your distDir (defaults to .next or is configured in your next.config.js). If your site is rooted in a subdirectory, your publish directory should be {yourSiteRoot}/{distDir}.' ,
267
+ )
257
268
} )
258
269
259
270
test ( 'restores cache with right paths' , async ( ) => {
@@ -286,9 +297,13 @@ describe('onBuild()', () => {
286
297
utils,
287
298
} )
288
299
289
- expect ( await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-handler/___netlify-handler.js` ) ) ) . toBeTruthy ( )
300
+ expect (
301
+ await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-handler/___netlify-handler.js` ) ) ,
302
+ ) . toBeTruthy ( )
290
303
expect ( await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-handler/bridge.js` ) ) ) . toBeTruthy ( )
291
- expect ( await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-odb-handler/___netlify-odb-handler.js` ) ) ) . toBeTruthy ( )
304
+ expect (
305
+ await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-odb-handler/___netlify-odb-handler.js` ) ) ,
306
+ ) . toBeTruthy ( )
292
307
expect ( await pathExists ( path . resolve ( `.netlify/internal-functions/___netlify-odb-handler/bridge.js` ) ) ) . toBeTruthy ( )
293
308
} )
294
309
0 commit comments