Skip to content

Commit

Permalink
Merge pull request #17 from achambers/add-read-config-to-plugin-helper
Browse files Browse the repository at this point in the history
Add  function to pluginHelper
lukemelia authored Nov 21, 2016
2 parents 201fa69 + 4a1e622 commit 8b121af
Showing 2 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@ function _pluginHelper() {
return cloneDeep(configuredValue.call(this, this.context));
}
return cloneDeep(configuredValue);
}.bind(this),

readConfig: function(property) {
return cloneDeep(this.readConfig(property));
}.bind(this)
};
}
68 changes: 67 additions & 1 deletion tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ describe('base plugin', function() {
},
writeLine: function(message) {
this.messages.push(message);
}
},
logInfoColor: 'blue'
};
});

@@ -174,5 +175,70 @@ describe('base plugin', function() {
assert.deepEqual(plugin.defaultConfig.distFiles, ['index.html', 'assets/logo.png']);
assert.deepEqual(plugin.defaultConfig.jsonBlueprint.link.attributes, ['rel', 'href']);
})

it('provides the ability to read the plugin config', function() {
var Plugin = Subject.extend({
defaultConfig: {
port: function() {
return 1234;
},
host: 'foo.com'
}
});

var plugin = new Plugin({
name: 'build'
});

var context = {
ui: mockUi,
config: {
build: {
username: 'bar',
options: function(context, pluginHelper) {
return {
port: pluginHelper.readConfig('port'),
host: pluginHelper.readConfig('host'),
username: pluginHelper.readConfig('username')
};
}
}
}
};

plugin.beforeHook(context);
plugin.configure(context);

assert.deepEqual(plugin.readConfig('options'), { port: 1234, host: 'foo.com', username: 'bar' });
});

it('doesn\'t mutate the original plugin config', function() {
var Plugin = Subject.extend({
defaultConfig: { }
});

var plugin = new Plugin({
name: 'build'
});

var context = {
ui: mockUi,
config: {
build: {
tags: ['foo'],
options: function(context, pluginHelper) {
var tags = pluginHelper.readConfig('tags');
tags.push('bar');
return { tags: tags };
}
}
}
};

plugin.beforeHook(context);
plugin.configure(context);

assert.deepEqual(plugin.readConfig('options'), { tags: ['foo', 'bar']});
});
});
});

0 comments on commit 8b121af

Please sign in to comment.