12
12
const expect = require ( 'chai' ) . expect ;
13
13
const api = require ( '../index' ) ;
14
14
15
- function configureApi ( ) {
16
- return api . configureRuntimeEnvironment ( 'dev' ) ;
17
- }
18
-
19
15
describe ( 'Public API' , ( ) => {
20
16
beforeEach ( ( ) => {
21
- api . clearRuntimeEnvironment ( ) ;
17
+ api . configureRuntimeEnvironment ( 'dev' ) ;
22
18
} ) ;
23
19
24
20
describe ( 'setOutputPath' , ( ) => {
25
21
26
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
27
- expect ( ( ) => api . setOutputPath ( '/' ) ) . to . throw ( ) ;
28
- } ) ;
29
-
30
22
it ( 'must return the API object' , ( ) => {
31
- configureApi ( ) ;
32
23
const returnedValue = api . setOutputPath ( '/' ) ;
33
24
expect ( returnedValue ) . to . equal ( api ) ;
34
25
} ) ;
@@ -37,12 +28,7 @@ describe('Public API', () => {
37
28
38
29
describe ( 'setPublicPath' , ( ) => {
39
30
40
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
41
- expect ( ( ) => api . setPublicPath ( '/' ) ) . to . throw ( ) ;
42
- } ) ;
43
-
44
31
it ( 'must return the API object' , ( ) => {
45
- configureApi ( ) ;
46
32
const returnedValue = api . setPublicPath ( '/' ) ;
47
33
expect ( returnedValue ) . to . equal ( api ) ;
48
34
} ) ;
@@ -51,12 +37,7 @@ describe('Public API', () => {
51
37
52
38
describe ( 'setManifestKeyPrefix' , ( ) => {
53
39
54
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
55
- expect ( ( ) => api . setManifestKeyPrefix ( '/build' ) ) . to . throw ( ) ;
56
- } ) ;
57
-
58
40
it ( 'must return the API object' , ( ) => {
59
- configureApi ( ) ;
60
41
const returnedValue = api . setManifestKeyPrefix ( '/build' ) ;
61
42
expect ( returnedValue ) . to . equal ( api ) ;
62
43
} ) ;
@@ -65,12 +46,7 @@ describe('Public API', () => {
65
46
66
47
describe ( 'addEntry' , ( ) => {
67
48
68
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
69
- expect ( ( ) => api . addEntry ( 'entry' , 'main.js' ) ) . to . throw ( ) ;
70
- } ) ;
71
-
72
49
it ( 'must return the API object' , ( ) => {
73
- configureApi ( ) ;
74
50
const returnedValue = api . addEntry ( 'entry' , 'main.js' ) ;
75
51
expect ( returnedValue ) . to . equal ( api ) ;
76
52
} ) ;
@@ -79,12 +55,7 @@ describe('Public API', () => {
79
55
80
56
describe ( 'addStyleEntry' , ( ) => {
81
57
82
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
83
- expect ( ( ) => api . addStyleEntry ( 'styleEntry' , 'main.css' ) ) . to . throw ( ) ;
84
- } ) ;
85
-
86
58
it ( 'must return the API object' , ( ) => {
87
- configureApi ( ) ;
88
59
const returnedValue = api . addStyleEntry ( 'styleEntry' , 'main.css' ) ;
89
60
expect ( returnedValue ) . to . equal ( api ) ;
90
61
} ) ;
@@ -93,12 +64,7 @@ describe('Public API', () => {
93
64
94
65
describe ( 'addPlugin' , ( ) => {
95
66
96
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
97
- expect ( ( ) => api . addPlugin ( null ) ) . to . throw ( ) ;
98
- } ) ;
99
-
100
67
it ( 'must return the API object' , ( ) => {
101
- configureApi ( ) ;
102
68
const returnedValue = api . addPlugin ( null ) ;
103
69
expect ( returnedValue ) . to . equal ( api ) ;
104
70
} ) ;
@@ -107,12 +73,7 @@ describe('Public API', () => {
107
73
108
74
describe ( 'addLoader' , ( ) => {
109
75
110
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
111
- expect ( ( ) => api . addLoader ( null ) ) . to . throw ( ) ;
112
- } ) ;
113
-
114
76
it ( 'must return the API object' , ( ) => {
115
- configureApi ( ) ;
116
77
const returnedValue = api . addLoader ( null ) ;
117
78
expect ( returnedValue ) . to . equal ( api ) ;
118
79
} ) ;
@@ -121,12 +82,7 @@ describe('Public API', () => {
121
82
122
83
describe ( 'addRule' , ( ) => {
123
84
124
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
125
- expect ( ( ) => api . addRule ( null ) ) . to . throw ( ) ;
126
- } ) ;
127
-
128
85
it ( 'must return the API object' , ( ) => {
129
- configureApi ( ) ;
130
86
const returnedValue = api . addRule ( null ) ;
131
87
expect ( returnedValue ) . to . equal ( api ) ;
132
88
} ) ;
@@ -135,12 +91,7 @@ describe('Public API', () => {
135
91
136
92
describe ( 'enableVersioning' , ( ) => {
137
93
138
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
139
- expect ( ( ) => api . enableVersioning ( ) ) . to . throw ( ) ;
140
- } ) ;
141
-
142
94
it ( 'must return the API object' , ( ) => {
143
- configureApi ( ) ;
144
95
const returnedValue = api . enableVersioning ( ) ;
145
96
expect ( returnedValue ) . to . equal ( api ) ;
146
97
} ) ;
@@ -149,12 +100,7 @@ describe('Public API', () => {
149
100
150
101
describe ( 'enableSourceMaps' , ( ) => {
151
102
152
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
153
- expect ( ( ) => api . enableSourceMaps ( ) ) . to . throw ( ) ;
154
- } ) ;
155
-
156
103
it ( 'must return the API object' , ( ) => {
157
- configureApi ( ) ;
158
104
const returnedValue = api . enableSourceMaps ( ) ;
159
105
expect ( returnedValue ) . to . equal ( api ) ;
160
106
} ) ;
@@ -163,12 +109,7 @@ describe('Public API', () => {
163
109
164
110
describe ( 'createSharedEntry' , ( ) => {
165
111
166
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
167
- expect ( ( ) => api . createSharedEntry ( 'sharedEntry' , 'vendor.js' ) ) . to . throw ( ) ;
168
- } ) ;
169
-
170
112
it ( 'must return the API object' , ( ) => {
171
- configureApi ( ) ;
172
113
const returnedValue = api . createSharedEntry ( 'sharedEntry' , 'vendor.js' ) ;
173
114
expect ( returnedValue ) . to . equal ( api ) ;
174
115
} ) ;
@@ -177,12 +118,7 @@ describe('Public API', () => {
177
118
178
119
describe ( 'autoProvideVariables' , ( ) => {
179
120
180
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
181
- expect ( ( ) => api . autoProvideVariables ( { } ) ) . to . throw ( ) ;
182
- } ) ;
183
-
184
121
it ( 'must return the API object' , ( ) => {
185
- configureApi ( ) ;
186
122
const returnedValue = api . autoProvideVariables ( { } ) ;
187
123
expect ( returnedValue ) . to . equal ( api ) ;
188
124
} ) ;
@@ -191,12 +127,7 @@ describe('Public API', () => {
191
127
192
128
describe ( 'autoProvidejQuery' , ( ) => {
193
129
194
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
195
- expect ( ( ) => api . autoProvidejQuery ( ) ) . to . throw ( ) ;
196
- } ) ;
197
-
198
130
it ( 'must return the API object' , ( ) => {
199
- configureApi ( ) ;
200
131
const returnedValue = api . autoProvidejQuery ( ) ;
201
132
expect ( returnedValue ) . to . equal ( api ) ;
202
133
} ) ;
@@ -205,12 +136,7 @@ describe('Public API', () => {
205
136
206
137
describe ( 'enablePostCssLoader' , ( ) => {
207
138
208
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
209
- expect ( ( ) => api . enablePostCssLoader ( ) ) . to . throw ( ) ;
210
- } ) ;
211
-
212
139
it ( 'must return the API object' , ( ) => {
213
- configureApi ( ) ;
214
140
const returnedValue = api . enablePostCssLoader ( ) ;
215
141
expect ( returnedValue ) . to . equal ( api ) ;
216
142
} ) ;
@@ -219,12 +145,7 @@ describe('Public API', () => {
219
145
220
146
describe ( 'enableSassLoader' , ( ) => {
221
147
222
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
223
- expect ( ( ) => api . enableSassLoader ( ) ) . to . throw ( ) ;
224
- } ) ;
225
-
226
148
it ( 'must return the API object' , ( ) => {
227
- configureApi ( ) ;
228
149
const returnedValue = api . enableSassLoader ( ) ;
229
150
expect ( returnedValue ) . to . equal ( api ) ;
230
151
} ) ;
@@ -233,12 +154,7 @@ describe('Public API', () => {
233
154
234
155
describe ( 'enableLessLoader' , ( ) => {
235
156
236
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
237
- expect ( ( ) => api . enableLessLoader ( ) ) . to . throw ( ) ;
238
- } ) ;
239
-
240
157
it ( 'must return the API object' , ( ) => {
241
- configureApi ( ) ;
242
158
const returnedValue = api . enableLessLoader ( ) ;
243
159
expect ( returnedValue ) . to . equal ( api ) ;
244
160
} ) ;
@@ -247,12 +163,7 @@ describe('Public API', () => {
247
163
248
164
describe ( 'setOutputPath' , ( ) => {
249
165
250
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
251
- expect ( ( ) => api . configureBabel ( ( ) => { } ) ) . to . throw ( ) ;
252
- } ) ;
253
-
254
166
it ( 'must return the API object' , ( ) => {
255
- configureApi ( ) ;
256
167
const returnedValue = api . configureBabel ( ( ) => { } ) ;
257
168
expect ( returnedValue ) . to . equal ( api ) ;
258
169
} ) ;
@@ -261,12 +172,7 @@ describe('Public API', () => {
261
172
262
173
describe ( 'enableReactPreset' , ( ) => {
263
174
264
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
265
- expect ( ( ) => api . enableReactPreset ( ) ) . to . throw ( ) ;
266
- } ) ;
267
-
268
175
it ( 'must return the API object' , ( ) => {
269
- configureApi ( ) ;
270
176
const returnedValue = api . enableReactPreset ( ) ;
271
177
expect ( returnedValue ) . to . equal ( api ) ;
272
178
} ) ;
@@ -275,12 +181,7 @@ describe('Public API', () => {
275
181
276
182
describe ( 'enableTypeScriptLoader' , ( ) => {
277
183
278
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
279
- expect ( ( ) => api . enableTypeScriptLoader ( ) ) . to . throw ( ) ;
280
- } ) ;
281
-
282
184
it ( 'must return the API object' , ( ) => {
283
- configureApi ( ) ;
284
185
const returnedValue = api . enableTypeScriptLoader ( ) ;
285
186
expect ( returnedValue ) . to . equal ( api ) ;
286
187
} ) ;
@@ -289,12 +190,7 @@ describe('Public API', () => {
289
190
290
191
describe ( 'enableVueLoader' , ( ) => {
291
192
292
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
293
- expect ( ( ) => api . enableVueLoader ( ) ) . to . throw ( ) ;
294
- } ) ;
295
-
296
193
it ( 'must return the API object' , ( ) => {
297
- configureApi ( ) ;
298
194
const returnedValue = api . enableVueLoader ( ) ;
299
195
expect ( returnedValue ) . to . equal ( api ) ;
300
196
} ) ;
@@ -303,12 +199,7 @@ describe('Public API', () => {
303
199
304
200
describe ( 'cleanupOutputBeforeBuild' , ( ) => {
305
201
306
- it ( 'should not be callable before the runtime environment has been configured' , ( ) => {
307
- expect ( ( ) => api . cleanupOutputBeforeBuild ( ) ) . to . throw ( ) ;
308
- } ) ;
309
-
310
202
it ( 'must return the API object' , ( ) => {
311
- configureApi ( ) ;
312
203
const returnedValue = api . cleanupOutputBeforeBuild ( ) ;
313
204
expect ( returnedValue ) . to . equal ( api ) ;
314
205
} ) ;
@@ -324,11 +215,17 @@ describe('Public API', () => {
324
215
325
216
} ) ;
326
217
327
- describe ( 'clearRuntimeEnvironment' , ( ) => {
218
+ describe ( 'Runtime environment proxy' , ( ) => {
219
+ beforeEach ( ( ) => {
220
+ api . clearRuntimeEnvironment ( ) ;
221
+ } ) ;
328
222
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' , ( ) => {
330
224
expect ( ( ) => api . clearRuntimeEnvironment ( ) ) . to . not . throw ( ) ;
331
225
} ) ;
332
226
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
+ } ) ;
333
230
} ) ;
334
231
} ) ;
0 commit comments