@@ -31,13 +31,13 @@ jest.mock('cpx')
31
31
// for why this log is required
32
32
console . log ( 'Initializing tests' )
33
33
34
+ const DUMMY_PACKAGE_JSON = { name : 'dummy' , version : '1.0.0' }
35
+
34
36
describe ( 'preBuild()' , ( ) => {
35
37
test ( 'fail build if the app has static html export in npm script' , async ( ) => {
36
- const packageJson = { scripts : { build : 'next export' } }
37
-
38
38
await plugin . onPreBuild ( {
39
39
netlifyConfig : { } ,
40
- packageJson,
40
+ packageJson : { ... DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
41
41
utils,
42
42
constants : { FUNCTIONS_SRC : 'out_functions' } ,
43
43
} )
@@ -49,11 +49,10 @@ describe('preBuild()', () => {
49
49
50
50
test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
51
51
const netlifyConfig = { build : { command : 'next build && next export' } }
52
- const packageJson = { }
53
52
54
53
await plugin . onPreBuild ( {
55
54
netlifyConfig,
56
- packageJson,
55
+ packageJson : DUMMY_PACKAGE_JSON ,
57
56
utils,
58
57
constants : { FUNCTIONS_SRC : 'out_functions' } ,
59
58
} )
@@ -63,12 +62,21 @@ describe('preBuild()', () => {
63
62
)
64
63
} )
65
64
66
- test ( 'fail build if the app has no functions directory defined' , async ( ) => {
67
- const packageJson = { }
65
+ test ( 'fail build if the app has no package.json' , async ( ) => {
66
+ await plugin . onPreBuild ( {
67
+ netlifyConfig : { } ,
68
+ packageJson : { } ,
69
+ utils,
70
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
71
+ } )
72
+
73
+ expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual ( `Could not find a package.json for this project` )
74
+ } )
68
75
76
+ test ( 'fail build if the app has no functions directory defined' , async ( ) => {
69
77
await plugin . onPreBuild ( {
70
78
netlifyConfig : { } ,
71
- packageJson,
79
+ packageJson : DUMMY_PACKAGE_JSON ,
72
80
utils,
73
81
constants : { } ,
74
82
} )
@@ -81,7 +89,7 @@ describe('preBuild()', () => {
81
89
test ( 'create next.config.js with correct target if file does not exist' , async ( ) => {
82
90
await plugin . onPreBuild ( {
83
91
netlifyConfig : { } ,
84
- packageJson : { } ,
92
+ packageJson : DUMMY_PACKAGE_JSON ,
85
93
utils,
86
94
constants : { FUNCTIONS_SRC : 'out_functions' } ,
87
95
} )
@@ -98,7 +106,7 @@ describe('preBuild()', () => {
98
106
99
107
await plugin . onPreBuild ( {
100
108
netlifyConfig : { } ,
101
- packageJson : { } ,
109
+ packageJson : DUMMY_PACKAGE_JSON ,
102
110
utils,
103
111
constants : { FUNCTIONS_SRC : 'out_functions' } ,
104
112
} )
0 commit comments