1212const expect = require ( 'chai' ) . expect ;
1313const api = require ( '../index' ) ;
1414
15- function configureApi ( ) {
16- return api . configureRuntimeEnvironment ( 'dev' ) ;
17- }
18-
1915describe ( 'Public API' , ( ) => {
2016 beforeEach ( ( ) => {
21- api . clearRuntimeEnvironment ( ) ;
17+ api . configureRuntimeEnvironment ( 'dev' ) ;
2218 } ) ;
2319
2420 describe ( 'setOutputPath' , ( ) => {
2521
26- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
27- expect ( ( ) => api . setOutputPath ( '/' ) ) . to . throw ( ) ;
28- } ) ;
29-
3022 it ( 'must return the API object' , ( ) => {
31- configureApi ( ) ;
3223 const returnedValue = api . setOutputPath ( '/' ) ;
3324 expect ( returnedValue ) . to . equal ( api ) ;
3425 } ) ;
@@ -37,12 +28,7 @@ describe('Public API', () => {
3728
3829 describe ( 'setPublicPath' , ( ) => {
3930
40- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
41- expect ( ( ) => api . setPublicPath ( '/' ) ) . to . throw ( ) ;
42- } ) ;
43-
4431 it ( 'must return the API object' , ( ) => {
45- configureApi ( ) ;
4632 const returnedValue = api . setPublicPath ( '/' ) ;
4733 expect ( returnedValue ) . to . equal ( api ) ;
4834 } ) ;
@@ -51,12 +37,7 @@ describe('Public API', () => {
5137
5238 describe ( 'setManifestKeyPrefix' , ( ) => {
5339
54- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
55- expect ( ( ) => api . setManifestKeyPrefix ( '/build' ) ) . to . throw ( ) ;
56- } ) ;
57-
5840 it ( 'must return the API object' , ( ) => {
59- configureApi ( ) ;
6041 const returnedValue = api . setManifestKeyPrefix ( '/build' ) ;
6142 expect ( returnedValue ) . to . equal ( api ) ;
6243 } ) ;
@@ -65,12 +46,7 @@ describe('Public API', () => {
6546
6647 describe ( 'addEntry' , ( ) => {
6748
68- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
69- expect ( ( ) => api . addEntry ( 'entry' , 'main.js' ) ) . to . throw ( ) ;
70- } ) ;
71-
7249 it ( 'must return the API object' , ( ) => {
73- configureApi ( ) ;
7450 const returnedValue = api . addEntry ( 'entry' , 'main.js' ) ;
7551 expect ( returnedValue ) . to . equal ( api ) ;
7652 } ) ;
@@ -79,12 +55,7 @@ describe('Public API', () => {
7955
8056 describe ( 'addStyleEntry' , ( ) => {
8157
82- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
83- expect ( ( ) => api . addStyleEntry ( 'styleEntry' , 'main.css' ) ) . to . throw ( ) ;
84- } ) ;
85-
8658 it ( 'must return the API object' , ( ) => {
87- configureApi ( ) ;
8859 const returnedValue = api . addStyleEntry ( 'styleEntry' , 'main.css' ) ;
8960 expect ( returnedValue ) . to . equal ( api ) ;
9061 } ) ;
@@ -93,12 +64,7 @@ describe('Public API', () => {
9364
9465 describe ( 'addPlugin' , ( ) => {
9566
96- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
97- expect ( ( ) => api . addPlugin ( null ) ) . to . throw ( ) ;
98- } ) ;
99-
10067 it ( 'must return the API object' , ( ) => {
101- configureApi ( ) ;
10268 const returnedValue = api . addPlugin ( null ) ;
10369 expect ( returnedValue ) . to . equal ( api ) ;
10470 } ) ;
@@ -107,12 +73,7 @@ describe('Public API', () => {
10773
10874 describe ( 'addLoader' , ( ) => {
10975
110- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
111- expect ( ( ) => api . addLoader ( null ) ) . to . throw ( ) ;
112- } ) ;
113-
11476 it ( 'must return the API object' , ( ) => {
115- configureApi ( ) ;
11677 const returnedValue = api . addLoader ( null ) ;
11778 expect ( returnedValue ) . to . equal ( api ) ;
11879 } ) ;
@@ -121,12 +82,7 @@ describe('Public API', () => {
12182
12283 describe ( 'addRule' , ( ) => {
12384
124- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
125- expect ( ( ) => api . addRule ( null ) ) . to . throw ( ) ;
126- } ) ;
127-
12885 it ( 'must return the API object' , ( ) => {
129- configureApi ( ) ;
13086 const returnedValue = api . addRule ( null ) ;
13187 expect ( returnedValue ) . to . equal ( api ) ;
13288 } ) ;
@@ -135,12 +91,7 @@ describe('Public API', () => {
13591
13692 describe ( 'enableVersioning' , ( ) => {
13793
138- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
139- expect ( ( ) => api . enableVersioning ( ) ) . to . throw ( ) ;
140- } ) ;
141-
14294 it ( 'must return the API object' , ( ) => {
143- configureApi ( ) ;
14495 const returnedValue = api . enableVersioning ( ) ;
14596 expect ( returnedValue ) . to . equal ( api ) ;
14697 } ) ;
@@ -149,12 +100,7 @@ describe('Public API', () => {
149100
150101 describe ( 'enableSourceMaps' , ( ) => {
151102
152- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
153- expect ( ( ) => api . enableSourceMaps ( ) ) . to . throw ( ) ;
154- } ) ;
155-
156103 it ( 'must return the API object' , ( ) => {
157- configureApi ( ) ;
158104 const returnedValue = api . enableSourceMaps ( ) ;
159105 expect ( returnedValue ) . to . equal ( api ) ;
160106 } ) ;
@@ -163,12 +109,7 @@ describe('Public API', () => {
163109
164110 describe ( 'createSharedEntry' , ( ) => {
165111
166- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
167- expect ( ( ) => api . createSharedEntry ( 'sharedEntry' , 'vendor.js' ) ) . to . throw ( ) ;
168- } ) ;
169-
170112 it ( 'must return the API object' , ( ) => {
171- configureApi ( ) ;
172113 const returnedValue = api . createSharedEntry ( 'sharedEntry' , 'vendor.js' ) ;
173114 expect ( returnedValue ) . to . equal ( api ) ;
174115 } ) ;
@@ -177,12 +118,7 @@ describe('Public API', () => {
177118
178119 describe ( 'autoProvideVariables' , ( ) => {
179120
180- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
181- expect ( ( ) => api . autoProvideVariables ( { } ) ) . to . throw ( ) ;
182- } ) ;
183-
184121 it ( 'must return the API object' , ( ) => {
185- configureApi ( ) ;
186122 const returnedValue = api . autoProvideVariables ( { } ) ;
187123 expect ( returnedValue ) . to . equal ( api ) ;
188124 } ) ;
@@ -191,12 +127,7 @@ describe('Public API', () => {
191127
192128 describe ( 'autoProvidejQuery' , ( ) => {
193129
194- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
195- expect ( ( ) => api . autoProvidejQuery ( ) ) . to . throw ( ) ;
196- } ) ;
197-
198130 it ( 'must return the API object' , ( ) => {
199- configureApi ( ) ;
200131 const returnedValue = api . autoProvidejQuery ( ) ;
201132 expect ( returnedValue ) . to . equal ( api ) ;
202133 } ) ;
@@ -205,12 +136,7 @@ describe('Public API', () => {
205136
206137 describe ( 'enablePostCssLoader' , ( ) => {
207138
208- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
209- expect ( ( ) => api . enablePostCssLoader ( ) ) . to . throw ( ) ;
210- } ) ;
211-
212139 it ( 'must return the API object' , ( ) => {
213- configureApi ( ) ;
214140 const returnedValue = api . enablePostCssLoader ( ) ;
215141 expect ( returnedValue ) . to . equal ( api ) ;
216142 } ) ;
@@ -219,12 +145,7 @@ describe('Public API', () => {
219145
220146 describe ( 'enableSassLoader' , ( ) => {
221147
222- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
223- expect ( ( ) => api . enableSassLoader ( ) ) . to . throw ( ) ;
224- } ) ;
225-
226148 it ( 'must return the API object' , ( ) => {
227- configureApi ( ) ;
228149 const returnedValue = api . enableSassLoader ( ) ;
229150 expect ( returnedValue ) . to . equal ( api ) ;
230151 } ) ;
@@ -233,12 +154,7 @@ describe('Public API', () => {
233154
234155 describe ( 'enableLessLoader' , ( ) => {
235156
236- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
237- expect ( ( ) => api . enableLessLoader ( ) ) . to . throw ( ) ;
238- } ) ;
239-
240157 it ( 'must return the API object' , ( ) => {
241- configureApi ( ) ;
242158 const returnedValue = api . enableLessLoader ( ) ;
243159 expect ( returnedValue ) . to . equal ( api ) ;
244160 } ) ;
@@ -247,12 +163,7 @@ describe('Public API', () => {
247163
248164 describe ( 'setOutputPath' , ( ) => {
249165
250- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
251- expect ( ( ) => api . configureBabel ( ( ) => { } ) ) . to . throw ( ) ;
252- } ) ;
253-
254166 it ( 'must return the API object' , ( ) => {
255- configureApi ( ) ;
256167 const returnedValue = api . configureBabel ( ( ) => { } ) ;
257168 expect ( returnedValue ) . to . equal ( api ) ;
258169 } ) ;
@@ -261,12 +172,7 @@ describe('Public API', () => {
261172
262173 describe ( 'enableReactPreset' , ( ) => {
263174
264- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
265- expect ( ( ) => api . enableReactPreset ( ) ) . to . throw ( ) ;
266- } ) ;
267-
268175 it ( 'must return the API object' , ( ) => {
269- configureApi ( ) ;
270176 const returnedValue = api . enableReactPreset ( ) ;
271177 expect ( returnedValue ) . to . equal ( api ) ;
272178 } ) ;
@@ -275,12 +181,7 @@ describe('Public API', () => {
275181
276182 describe ( 'enableTypeScriptLoader' , ( ) => {
277183
278- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
279- expect ( ( ) => api . enableTypeScriptLoader ( ) ) . to . throw ( ) ;
280- } ) ;
281-
282184 it ( 'must return the API object' , ( ) => {
283- configureApi ( ) ;
284185 const returnedValue = api . enableTypeScriptLoader ( ) ;
285186 expect ( returnedValue ) . to . equal ( api ) ;
286187 } ) ;
@@ -289,12 +190,7 @@ describe('Public API', () => {
289190
290191 describe ( 'enableVueLoader' , ( ) => {
291192
292- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
293- expect ( ( ) => api . enableVueLoader ( ) ) . to . throw ( ) ;
294- } ) ;
295-
296193 it ( 'must return the API object' , ( ) => {
297- configureApi ( ) ;
298194 const returnedValue = api . enableVueLoader ( ) ;
299195 expect ( returnedValue ) . to . equal ( api ) ;
300196 } ) ;
@@ -303,12 +199,7 @@ describe('Public API', () => {
303199
304200 describe ( 'cleanupOutputBeforeBuild' , ( ) => {
305201
306- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
307- expect ( ( ) => api . cleanupOutputBeforeBuild ( ) ) . to . throw ( ) ;
308- } ) ;
309-
310202 it ( 'must return the API object' , ( ) => {
311- configureApi ( ) ;
312203 const returnedValue = api . cleanupOutputBeforeBuild ( ) ;
313204 expect ( returnedValue ) . to . equal ( api ) ;
314205 } ) ;
@@ -324,11 +215,17 @@ describe('Public API', () => {
324215
325216 } ) ;
326217
327- describe ( 'clearRuntimeEnvironment' , ( ) => {
218+ describe ( 'Runtime environment proxy' , ( ) => {
219+ beforeEach ( ( ) => {
220+ api . clearRuntimeEnvironment ( ) ;
221+ } ) ;
328222
329- it ( 'should be callable even if the runtime environment has not been configured' , ( ) => {
223+ it ( 'safe methods should be callable even if the runtime environment has not been configured' , ( ) => {
330224 expect ( ( ) => api . clearRuntimeEnvironment ( ) ) . to . not . throw ( ) ;
331225 } ) ;
332226
227+ it ( 'unsafe methods should NOT be callable if the runtime environment has not been configured' , ( ) => {
228+ expect ( ( ) => api . setOutputPath ( '/' ) ) . to . throw ( 'Encore.setOutputPath() cannot be called yet' ) ;
229+ } ) ;
333230 } ) ;
334231} ) ;
0 commit comments