@@ -61,71 +61,74 @@ const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
61
61
const netlifyConfig = { build : { } }
62
62
63
63
describe ( 'preBuild()' , ( ) => {
64
- test ( 'fail build if the app has static html export in npm script' , async ( ) => {
65
- await expect (
66
- plugin . onPreBuild ( {
67
- netlifyConfig : { build : { command : 'npm run build' } } ,
68
- packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
69
- utils,
70
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
71
- } ) ,
72
- ) . rejects . toThrow (
73
- `Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.` ,
74
- )
64
+ test ( 'create next.config.js with correct target if file does not exist' , async ( ) => {
65
+ await plugin . onPreBuild ( {
66
+ netlifyConfig,
67
+ packageJson : DUMMY_PACKAGE_JSON ,
68
+ utils,
69
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
70
+ } )
71
+
72
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeTruthy ( )
75
73
} )
76
74
77
- test ( 'do not fail build if the app has next export in an unused script' , async ( ) => {
78
- await expect (
79
- plugin . onPreBuild ( {
80
- netlifyConfig ,
81
- packageJson : { ... DUMMY_PACKAGE_JSON , scripts : { export : 'next export' } } ,
82
- utils ,
83
- constants : { } ,
84
- } ) ,
85
- ) . resolves
75
+ test ( 'do nothing if the app has static html export in npm script' , async ( ) => {
76
+ await plugin . onPreBuild ( {
77
+ netlifyConfig : { build : { command : 'npm run build' } } ,
78
+ packageJson : { ... DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
79
+ utils ,
80
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
81
+ } )
82
+
83
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeFalsy ( )
86
84
} )
87
85
88
- test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
89
- await expect (
90
- plugin . onPreBuild ( {
91
- netlifyConfig : { build : { command : 'next build && next export' } } ,
92
- packageJson : DUMMY_PACKAGE_JSON ,
93
- utils,
94
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
95
- } ) ,
96
- ) . rejects . toThrow (
97
- `Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.` ,
98
- )
86
+ test ( 'run plugin if the app has next export in an unused script' , async ( ) => {
87
+ await plugin . onPreBuild ( {
88
+ netlifyConfig,
89
+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { export : 'next export' } } ,
90
+ utils,
91
+ constants : { } ,
92
+ } )
93
+
94
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeTruthy ( )
99
95
} )
100
96
101
- test ( 'fail build if app has next-on-netlify installed' , async ( ) => {
97
+ test ( 'do nothing if app has static html export in toml/ntl config' , async ( ) => {
98
+ await plugin . onPreBuild ( {
99
+ netlifyConfig : { build : { command : 'next build && next export' } } ,
100
+ packageJson : DUMMY_PACKAGE_JSON ,
101
+ utils,
102
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
103
+ } )
104
+
105
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeFalsy ( )
106
+ } )
107
+
108
+ test ( 'do nothing if app has next-on-netlify installed' , async ( ) => {
102
109
const packageJson = {
103
110
dependencies : { 'next-on-netlify' : '123' } ,
104
111
}
105
- await expect (
106
- plugin . onPreBuild ( {
107
- netlifyConfig,
108
- packageJson,
109
- utils,
110
- } ) ,
111
- ) . rejects . toThrow (
112
- `This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.` ,
113
- )
112
+ await plugin . onPreBuild ( {
113
+ netlifyConfig,
114
+ packageJson,
115
+ utils,
116
+ } )
117
+
118
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeFalsy ( )
114
119
} )
115
120
116
- test ( 'fail build if app has next-on-netlify postbuild script' , async ( ) => {
121
+ test ( 'do nothing if app has next-on-netlify postbuild script' , async ( ) => {
117
122
const packageJson = {
118
123
scripts : { postbuild : 'next-on-netlify' } ,
119
124
}
120
- await expect (
121
- plugin . onPreBuild ( {
122
- netlifyConfig,
123
- packageJson,
124
- utils,
125
- } ) ,
126
- ) . rejects . toThrow (
127
- `This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.` ,
128
- )
125
+ await plugin . onPreBuild ( {
126
+ netlifyConfig,
127
+ packageJson,
128
+ utils,
129
+ } )
130
+
131
+ expect ( await pathExists ( 'next.config.js' ) ) . toBeFalsy ( )
129
132
} )
130
133
131
134
test ( 'fail build if the app has no package.json' , async ( ) => {
@@ -138,42 +141,48 @@ describe('preBuild()', () => {
138
141
} ) ,
139
142
) . rejects . toThrow ( `Could not find a package.json for this project` )
140
143
} )
144
+ } )
141
145
142
- test ( 'create next.config.js with correct target if file does not exist' , async ( ) => {
143
- await plugin . onPreBuild ( {
146
+ describe ( 'onBuild()' , ( ) => {
147
+ test ( 'does not run onBuild if using next-on-netlify' , async ( ) => {
148
+ const packageJson = {
149
+ scripts : { postbuild : 'next-on-netlify' } ,
150
+ }
151
+ await useFixture ( 'publish_copy_files' )
152
+ await moveNextDist ( )
153
+ const PUBLISH_DIR = 'publish'
154
+ await plugin . onBuild ( {
144
155
netlifyConfig,
145
- packageJson : DUMMY_PACKAGE_JSON ,
146
- utils,
147
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
156
+ packageJson,
157
+ constants : { } ,
148
158
} )
149
159
150
- expect ( await pathExists ( 'next.config.js' ) ) . toBeTruthy ( )
160
+ expect ( await pathExists ( ` ${ PUBLISH_DIR } /index.html` ) ) . toBeFalsy ( )
151
161
} )
152
162
153
163
test . each ( [ 'invalid_next_config' , 'deep_invalid_next_config' ] ) (
154
- `fail build if the app's next config has an invalid target` ,
164
+ `do nothing if the app's next config has an invalid target` ,
155
165
async ( fixtureName ) => {
156
166
await useFixture ( fixtureName )
157
- await expect (
158
- plugin . onPreBuild ( {
159
- netlifyConfig,
160
- packageJson : DUMMY_PACKAGE_JSON ,
161
- utils,
162
- constants : { FUNCTIONS_SRC : 'out_functions' } ,
163
- } ) ,
164
- ) . rejects . toThrow (
165
- `Your next.config.js must set the "target" property to one of: serverless, experimental-serverless-trace` ,
166
- )
167
+ const PUBLISH_DIR = 'publish'
168
+ await plugin . onBuild ( {
169
+ netlifyConfig,
170
+ packageJson : DUMMY_PACKAGE_JSON ,
171
+ utils,
172
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
173
+ } )
174
+
175
+ expect ( await pathExists ( `${ PUBLISH_DIR } /index.html` ) ) . toBeFalsy ( )
167
176
} ,
168
177
)
169
- } )
170
178
171
- describe ( 'onBuild()' , ( ) => {
172
179
test ( 'copy files to the publish directory' , async ( ) => {
173
180
await useFixture ( 'publish_copy_files' )
174
181
await moveNextDist ( )
175
182
const PUBLISH_DIR = 'publish'
176
183
await plugin . onBuild ( {
184
+ netlifyConfig,
185
+ packageJson : DUMMY_PACKAGE_JSON ,
177
186
constants : {
178
187
PUBLISH_DIR ,
179
188
FUNCTIONS_SRC : 'functions' ,
@@ -191,6 +200,8 @@ describe('onBuild()', () => {
191
200
await useFixture ( 'functions_copy_files' )
192
201
await moveNextDist ( )
193
202
await plugin . onBuild ( {
203
+ netlifyConfig,
204
+ packageJson : DUMMY_PACKAGE_JSON ,
194
205
constants : {
195
206
FUNCTIONS_SRC ,
196
207
PUBLISH_DIR : '.' ,
0 commit comments