@@ -21,7 +21,8 @@ describe('base plugin', function() {
21
21
} ,
22
22
writeLine : function ( message ) {
23
23
this . messages . push ( message ) ;
24
- }
24
+ } ,
25
+ logInfoColor : 'blue'
25
26
} ;
26
27
} ) ;
27
28
@@ -174,5 +175,70 @@ describe('base plugin', function() {
174
175
assert . deepEqual ( plugin . defaultConfig . distFiles , [ 'index.html' , 'assets/logo.png' ] ) ;
175
176
assert . deepEqual ( plugin . defaultConfig . jsonBlueprint . link . attributes , [ 'rel' , 'href' ] ) ;
176
177
} )
178
+
179
+ it ( 'provides the ability to read the plugin config' , function ( ) {
180
+ var Plugin = Subject . extend ( {
181
+ defaultConfig : {
182
+ port : function ( ) {
183
+ return 1234 ;
184
+ } ,
185
+ host : 'foo.com'
186
+ }
187
+ } ) ;
188
+
189
+ var plugin = new Plugin ( {
190
+ name : 'build'
191
+ } ) ;
192
+
193
+ var context = {
194
+ ui : mockUi ,
195
+ config : {
196
+ build : {
197
+ username : 'bar' ,
198
+ options : function ( context , pluginHelper ) {
199
+ return {
200
+ port : pluginHelper . readConfig ( 'port' ) ,
201
+ host : pluginHelper . readConfig ( 'host' ) ,
202
+ username : pluginHelper . readConfig ( 'username' )
203
+ } ;
204
+ }
205
+ }
206
+ }
207
+ } ;
208
+
209
+ plugin . beforeHook ( context ) ;
210
+ plugin . configure ( context ) ;
211
+
212
+ assert . deepEqual ( plugin . readConfig ( 'options' ) , { port : 1234 , host : 'foo.com' , username : 'bar' } ) ;
213
+ } ) ;
214
+
215
+ it ( 'doesn\'t mutate the original plugin config' , function ( ) {
216
+ var Plugin = Subject . extend ( {
217
+ defaultConfig : { }
218
+ } ) ;
219
+
220
+ var plugin = new Plugin ( {
221
+ name : 'build'
222
+ } ) ;
223
+
224
+ var context = {
225
+ ui : mockUi ,
226
+ config : {
227
+ build : {
228
+ tags : [ 'foo' ] ,
229
+ options : function ( context , pluginHelper ) {
230
+ var tags = pluginHelper . readConfig ( 'tags' ) ;
231
+ tags . push ( 'bar' ) ;
232
+ return { tags : tags } ;
233
+ }
234
+ }
235
+ }
236
+ } ;
237
+
238
+ plugin . beforeHook ( context ) ;
239
+ plugin . configure ( context ) ;
240
+
241
+ assert . deepEqual ( plugin . readConfig ( 'options' ) , { tags : [ 'foo' , 'bar' ] } ) ;
242
+ } ) ;
177
243
} ) ;
178
244
} ) ;
0 commit comments