Skip to content

Commit 4a1e622

Browse files
committed
Add function to pluginHelper
1 parent 201fa69 commit 4a1e622

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function _pluginHelper() {
1010
return cloneDeep(configuredValue.call(this, this.context));
1111
}
1212
return cloneDeep(configuredValue);
13+
}.bind(this),
14+
15+
readConfig: function(property) {
16+
return cloneDeep(this.readConfig(property));
1317
}.bind(this)
1418
};
1519
}

tests/unit/index-nodetest.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('base plugin', function() {
2121
},
2222
writeLine: function(message) {
2323
this.messages.push(message);
24-
}
24+
},
25+
logInfoColor: 'blue'
2526
};
2627
});
2728

@@ -174,5 +175,70 @@ describe('base plugin', function() {
174175
assert.deepEqual(plugin.defaultConfig.distFiles, ['index.html', 'assets/logo.png']);
175176
assert.deepEqual(plugin.defaultConfig.jsonBlueprint.link.attributes, ['rel', 'href']);
176177
})
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+
});
177243
});
178244
});

0 commit comments

Comments
 (0)