@@ -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
} )
43
43
@@ -48,11 +48,10 @@ describe('preBuild()', () => {
48
48
49
49
test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
50
50
const netlifyConfig = { build : { command : 'next build && next export' } }
51
- const packageJson = { }
52
51
53
52
await plugin . onPreBuild ( {
54
53
netlifyConfig,
55
- packageJson,
54
+ packageJson : DUMMY_PACKAGE_JSON ,
56
55
utils,
57
56
} )
58
57
@@ -61,13 +60,22 @@ describe('preBuild()', () => {
61
60
)
62
61
} )
63
62
63
+ test ( 'fail build if the app has no package.json' , async ( ) => {
64
+ await plugin . onPreBuild ( {
65
+ netlifyConfig : { } ,
66
+ packageJson : { } ,
67
+ utils,
68
+ } )
69
+
70
+ expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual ( `Could not find a package.json for this project` )
71
+ } )
72
+
64
73
test ( 'fail build if the app has no functions directory defined' , async ( ) => {
65
74
const netlifyConfig = { build : { } }
66
- const packageJson = { }
67
75
68
76
await plugin . onPreBuild ( {
69
77
netlifyConfig,
70
- packageJson,
78
+ packageJson : DUMMY_PACKAGE_JSON ,
71
79
utils,
72
80
} )
73
81
@@ -79,7 +87,7 @@ describe('preBuild()', () => {
79
87
test ( 'create next.config.js with correct target if file does not exist' , async ( ) => {
80
88
await plugin . onPreBuild ( {
81
89
netlifyConfig : { } ,
82
- packageJson : { } ,
90
+ packageJson : DUMMY_PACKAGE_JSON ,
83
91
utils,
84
92
} )
85
93
@@ -96,7 +104,7 @@ describe('preBuild()', () => {
96
104
97
105
await plugin . onPreBuild ( {
98
106
netlifyConfig,
99
- packageJson : { } ,
107
+ packageJson : DUMMY_PACKAGE_JSON ,
100
108
utils,
101
109
} )
102
110
0 commit comments