@@ -2,12 +2,14 @@ import path from 'path'
2
2
import process from 'process'
3
3
import { fileURLToPath } from 'url'
4
4
5
+ import { load } from 'cheerio'
5
6
import execa from 'execa'
6
7
import fetch from 'node-fetch'
7
- import { afterAll , beforeAll , describe , test } from 'vitest'
8
+ import { afterAll , beforeAll , describe , expect , test } from 'vitest'
8
9
9
10
import { callCli } from '../../utils/call-cli.js'
10
11
import { createLiveTestSite , generateSiteName } from '../../utils/create-live-test-site.js'
12
+ import { FixtureTestContext , setupFixtureTests } from '../../utils/fixture.js'
11
13
import { pause } from '../../utils/pause.js'
12
14
import { withSiteBuilder } from '../../utils/site-builder.ts'
13
15
@@ -16,29 +18,41 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
16
18
17
19
const SITE_NAME = generateSiteName ( 'netlify-test-deploy-' )
18
20
19
- // eslint-disable-next-line no-shadow
20
- const validateContent = async ( { content, path, siteUrl, t } ) => {
21
- const response = await fetch ( `${ siteUrl } ${ path } ` )
21
+ const validateContent = async ( { content, path : pathname , siteUrl } ) => {
22
+ const response = await fetch ( `${ siteUrl } ${ pathname } ` )
22
23
const body = await response . text ( )
23
24
if ( content === undefined ) {
24
- t . expect ( response . status ) . toBe ( 404 )
25
+ expect ( response . status ) . toBe ( 404 )
25
26
return
26
27
}
27
- t . expect ( response . status , `status should be 200. request id: ${ response . headers . get ( 'x-nf-request-id' ) } ` ) . toBe ( 200 )
28
- t . expect ( body , `body should be as expected. request id: ${ response . headers . get ( 'x-nf-request-id' ) } ` ) . toEqual ( content )
28
+ expect ( response . status , `status should be 200. request id: ${ response . headers . get ( 'x-nf-request-id' ) } ` ) . toBe ( 200 )
29
+ expect ( body , `body should be as expected. request id: ${ response . headers . get ( 'x-nf-request-id' ) } ` ) . toEqual ( content )
29
30
}
30
31
31
- const validateDeploy = async ( { content, contentMessage, deploy, siteName, t } ) => {
32
- t . expect ( deploy . site_name ) . toBeTruthy ( )
33
- t . expect ( deploy . deploy_url ) . toBeTruthy ( )
34
- t . expect ( deploy . deploy_id ) . toBeTruthy ( )
35
- t . expect ( deploy . logs ) . toBeTruthy ( )
36
- t . expect ( deploy . site_name , contentMessage ) . toEqual ( siteName )
37
-
38
- await validateContent ( { siteUrl : deploy . deploy_url , path : '' , content, t } )
32
+ const validateDeploy = async ( {
33
+ content,
34
+ contentMessage,
35
+ deploy,
36
+ siteName,
37
+ } : {
38
+ contentMessage ?: string
39
+ siteName : string
40
+ content ?: string
41
+ deploy : { site_name : string ; deploy_url : string ; deploy_id : string ; logs : string }
42
+ } ) => {
43
+ expect ( deploy . site_name ) . toBeTruthy ( )
44
+ expect ( deploy . deploy_url ) . toBeTruthy ( )
45
+ expect ( deploy . deploy_id ) . toBeTruthy ( )
46
+ expect ( deploy . logs ) . toBeTruthy ( )
47
+ expect ( deploy . site_name , contentMessage ) . toEqual ( siteName )
48
+
49
+ await validateContent ( { siteUrl : deploy . deploy_url , path : '' , content } )
39
50
}
40
51
41
- const context = { }
52
+ const context : { account : unknown ; siteId : string } = {
53
+ siteId : '' ,
54
+ account : undefined ,
55
+ }
42
56
43
57
describe . skipIf ( process . env . NETLIFY_TEST_DISABLE_LIVE === 'true' ) . concurrent ( 'commands/deploy' , ( ) => {
44
58
beforeAll ( async ( ) => {
@@ -68,7 +82,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
68
82
env : { NETLIFY_SITE_ID : context . siteId } ,
69
83
} ) . then ( ( output ) => JSON . parse ( output ) )
70
84
71
- await validateDeploy ( { deploy, siteName : SITE_NAME , content, t } )
85
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content } )
72
86
} )
73
87
} )
74
88
@@ -92,7 +106,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
92
106
cwd : builder . directory ,
93
107
} ) . then ( ( output ) => JSON . parse ( output ) )
94
108
95
- await validateDeploy ( { deploy, siteName : SITE_NAME , content, t } )
109
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content } )
96
110
} )
97
111
} )
98
112
@@ -117,7 +131,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
117
131
env : { NETLIFY_SITE_ID : context . siteId } ,
118
132
} ) . then ( ( output ) => JSON . parse ( output ) )
119
133
120
- await validateDeploy ( { deploy, siteName : SITE_NAME , content, t } )
134
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content } )
121
135
} )
122
136
} )
123
137
@@ -158,7 +172,6 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
158
172
siteName : SITE_NAME ,
159
173
content : 'Edge Function works' ,
160
174
contentMessage : 'Edge function did not execute correctly or was not deployed correctly' ,
161
- t,
162
175
} )
163
176
} )
164
177
} )
@@ -205,7 +218,6 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
205
218
siteName : SITE_NAME ,
206
219
content : 'Edge Function works' ,
207
220
contentMessage : 'Edge function did not execute correctly or was not deployed correctly' ,
208
- t,
209
221
} )
210
222
} )
211
223
} )
@@ -228,7 +240,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
228
240
name : 'log-env' ,
229
241
plugin : {
230
242
async onSuccess ( ) {
231
- // eslint-disable-next-line n/global-require, no-undef
243
+ // eslint-disable-next-line n/global-require, @typescript-eslint/ no-var-requires
232
244
const { DEPLOY_ID , DEPLOY_URL } = require ( 'process' ) . env
233
245
console . log ( `DEPLOY_ID: ${ DEPLOY_ID } ` )
234
246
console . log ( `DEPLOY_URL: ${ DEPLOY_URL } ` )
@@ -310,24 +322,21 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
310
322
env : { NETLIFY_SITE_ID : context . siteId } ,
311
323
} ) . then ( ( output ) => JSON . parse ( output ) )
312
324
313
- await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' , t } )
325
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' } )
314
326
await validateContent ( {
315
327
siteUrl : deploy . deploy_url ,
316
328
content : undefined ,
317
329
path : '/.hidden-file' ,
318
- t,
319
330
} )
320
331
await validateContent ( {
321
332
siteUrl : deploy . deploy_url ,
322
333
content : undefined ,
323
334
path : '/.hidden-dir' ,
324
- t,
325
335
} )
326
336
await validateContent ( {
327
337
siteUrl : deploy . deploy_url ,
328
338
content : undefined ,
329
339
path : '/__MACOSX' ,
330
- t,
331
340
} )
332
341
} )
333
342
} )
@@ -358,12 +367,11 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
358
367
env : { NETLIFY_SITE_ID : context . siteId } ,
359
368
} ) . then ( ( output ) => JSON . parse ( output ) )
360
369
361
- await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' , t } )
370
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' } )
362
371
await validateContent ( {
363
372
siteUrl : deploy . deploy_url ,
364
373
content : undefined ,
365
374
path : '/node_modules/package.json' ,
366
- t,
367
375
} )
368
376
} )
369
377
} )
@@ -394,12 +402,11 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
394
402
env : { NETLIFY_SITE_ID : context . siteId } ,
395
403
} ) . then ( ( output ) => JSON . parse ( output ) )
396
404
397
- await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' , t } )
405
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content : 'index' } )
398
406
await validateContent ( {
399
407
siteUrl : deploy . deploy_url ,
400
408
content : '{}' ,
401
409
path : '/node_modules/package.json' ,
402
- t,
403
410
} )
404
411
} )
405
412
} )
@@ -414,7 +421,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
414
421
env : { NETLIFY_SITE_ID : context . siteId } ,
415
422
} )
416
423
} catch ( error ) {
417
- t . expect ( error . stderr . includes ( 'Error: No files or functions to deploy' ) ) . toBe ( true )
424
+ expect ( error . stderr . includes ( 'Error: No files or functions to deploy' ) ) . toBe ( true )
418
425
}
419
426
} )
420
427
} )
@@ -437,7 +444,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
437
444
name : 'mutator' ,
438
445
plugin : {
439
446
onPreBuild : async ( { netlifyConfig } ) => {
440
- // eslint-disable-next-line no-undef, n/global-require
447
+ // eslint-disable-next-line n/global-require, @typescript-eslint/no-var-requires
441
448
const { mkdir, writeFile } = require ( 'fs/promises' )
442
449
443
450
const generatedFunctionsDir = 'new_functions'
@@ -690,7 +697,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
690
697
const redirectsMessage = fullDeploy . summary . messages . find ( ( { title } ) => title === '3 redirect rules processed' )
691
698
t . expect ( redirectsMessage . description ) . toEqual ( 'All redirect rules deployed without errors.' )
692
699
693
- await validateDeploy ( { deploy, siteName : SITE_NAME , content, t } )
700
+ await validateDeploy ( { deploy, siteName : SITE_NAME , content } )
694
701
695
702
const [ pluginRedirectResponse , _redirectsResponse , netlifyTomResponse ] = await Promise . all ( [
696
703
fetch ( `${ deploy . deploy_url } /other-api/hello` ) . then ( ( res ) => res . text ( ) ) ,
@@ -762,7 +769,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
762
769
true ,
763
770
)
764
771
const response = await fetch ( `${ deployUrl } /.netlify/functions/bundled-function-1` ) . then ( ( res ) => res . text ( ) )
765
- t . expect ( response ) . toEqual ( 'Pre-bundled' )
772
+ expect ( response ) . toEqual ( 'Pre-bundled' )
766
773
} )
767
774
} )
768
775
@@ -945,4 +952,26 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
945
952
t . expect ( response ) . toEqual ( 'hello from the blob' )
946
953
} )
947
954
} )
955
+
956
+ setupFixtureTests ( 'next-app-without-config' , ( ) => {
957
+ test < FixtureTestContext > ( 'should run deploy with --build without any netlify specific configuration' , async ( {
958
+ fixture,
959
+ } ) => {
960
+ const { deploy_url : deployUrl } = await callCli (
961
+ [ 'deploy' , '--build' , '--json' ] ,
962
+ {
963
+ cwd : fixture . directory ,
964
+ env : { NETLIFY_SITE_ID : context . siteId } ,
965
+ } ,
966
+ true ,
967
+ )
968
+
969
+ const html = await fetch ( deployUrl ) . then ( ( res ) => res . text ( ) )
970
+ // eslint-disable-next-line id-length
971
+ const $ = load ( html )
972
+
973
+ expect ( $ ( 'title' ) . text ( ) ) . toEqual ( 'Create Next App' )
974
+ expect ( $ ( 'img[alt="Next.js Logo"]' ) . attr ( 'src' ) ) . toBe ( '/next.svg' )
975
+ } )
976
+ } )
948
977
} )
2 commit comments
github-actions[bot] commentedon Jul 15, 2024
📊 Benchmark results
github-actions[bot] commentedon Jul 15, 2024
📊 Benchmark results