@@ -61,71 +61,58 @@ 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 ( 'do nothing if the app has static html export in npm script' , async ( ) => {
65
+ const output = await plugin . onPreBuild ( {
66
+ netlifyConfig : { build : { command : 'npm run build' } } ,
67
+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
68
+ utils,
69
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
70
+ } )
71
+ expect ( output ) . toBe ( undefined )
75
72
} )
76
73
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
74
+ test ( 'run plugin if the app has next export in an unused script' , async ( ) => {
75
+ const output = await plugin . onPreBuild ( {
76
+ netlifyConfig,
77
+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { export : 'next export' } } ,
78
+ utils,
79
+ constants : { } ,
80
+ } )
81
+ expect ( output ) . toBe ( true )
86
82
} )
87
83
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
- )
84
+ test ( 'do nothing if app has static html export in toml/ntl config' , async ( ) => {
85
+ const output = await plugin . onPreBuild ( {
86
+ netlifyConfig : { build : { command : 'next build && next export' } } ,
87
+ packageJson : DUMMY_PACKAGE_JSON ,
88
+ utils,
89
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
90
+ } )
91
+ expect ( output ) . toBe ( undefined )
99
92
} )
100
93
101
- test ( 'fail build if app has next-on-netlify installed' , async ( ) => {
94
+ test ( 'do nothing if app has next-on-netlify installed' , async ( ) => {
102
95
const packageJson = {
103
96
dependencies : { 'next-on-netlify' : '123' } ,
104
97
}
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
- )
98
+ const output = await plugin . onPreBuild ( {
99
+ netlifyConfig,
100
+ packageJson,
101
+ utils,
102
+ } )
103
+ expect ( output ) . toBe ( undefined )
114
104
} )
115
105
116
- test ( 'fail build if app has next-on-netlify postbuild script' , async ( ) => {
106
+ test ( 'do nothing if app has next-on-netlify postbuild script' , async ( ) => {
117
107
const packageJson = {
118
108
scripts : { postbuild : 'next-on-netlify' } ,
119
109
}
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
- )
110
+ const output = await plugin . onPreBuild ( {
111
+ netlifyConfig,
112
+ packageJson,
113
+ utils,
114
+ } )
115
+ expect ( output ) . toBe ( undefined )
129
116
} )
130
117
131
118
test ( 'fail build if the app has no package.json' , async ( ) => {
@@ -151,19 +138,16 @@ describe('preBuild()', () => {
151
138
} )
152
139
153
140
test . each ( [ 'invalid_next_config' , 'deep_invalid_next_config' ] ) (
154
- `fail build if the app's next config has an invalid target` ,
141
+ `do nothing if the app's next config has an invalid target` ,
155
142
async ( fixtureName ) => {
156
143
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
- )
144
+ const output = await plugin . onPreBuild ( {
145
+ netlifyConfig,
146
+ packageJson : DUMMY_PACKAGE_JSON ,
147
+ utils,
148
+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
149
+ } )
150
+ expect ( output ) . toBe ( undefined )
167
151
} ,
168
152
)
169
153
} )
@@ -174,6 +158,8 @@ describe('onBuild()', () => {
174
158
await moveNextDist ( )
175
159
const PUBLISH_DIR = 'publish'
176
160
await plugin . onBuild ( {
161
+ netlifyConfig,
162
+ packageJson : DUMMY_PACKAGE_JSON ,
177
163
constants : {
178
164
PUBLISH_DIR ,
179
165
FUNCTIONS_SRC : 'functions' ,
@@ -191,6 +177,8 @@ describe('onBuild()', () => {
191
177
await useFixture ( 'functions_copy_files' )
192
178
await moveNextDist ( )
193
179
await plugin . onBuild ( {
180
+ netlifyConfig,
181
+ packageJson : DUMMY_PACKAGE_JSON ,
194
182
constants : {
195
183
FUNCTIONS_SRC ,
196
184
PUBLISH_DIR : '.' ,
0 commit comments