Skip to content

Commit

Permalink
Pass floatPrecision to implemented plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Mar 5, 2021
1 parent 76c7719 commit d58a7e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/svgo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const resolvePluginConfig = (plugin, config) => {
return {
active: true,
...plugin,
params: { configParams, ...plugin.params },
params: { ...configParams, ...plugin.params },
};
} else {
// resolve builtin plugin specified as object without implementation
Expand Down
21 changes: 15 additions & 6 deletions test/config/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,36 @@ describe('config', function () {
const config = {
multipass: true,
floatPrecision: 2,
plugins: [{ name: 'cleanupNumericValues' }],
plugins: [
'convertPathData',
{ name: 'cleanupNumericValues' },
{ name: 'customPlugin', fn: () => {} },
],
};
const plugins = config.plugins.map((plugin) =>
resolvePluginConfig(plugin, config)
);
const cleanupNumericValues = getPlugin('cleanupNumericValues', plugins);
const convertPathData = getPlugin('convertPathData', plugins);
const customPlugin = getPlugin('customPlugin', plugins);

it('should have "multipass"', function () {
expect(config.multipass).to.be.true;
});

it('config.plugins should have length 1', function () {
expect(plugins).to.have.length(1);
it('config.plugins should have length 3', function () {
expect(plugins).to.have.length(3);
});

it('cleanupNumericValues plugin should be enabled', function () {
expect(cleanupNumericValues.active).to.be.true;
it('specified plugins should be enabled', function () {
expect(cleanupNumericValues.active).to.equal(true);
expect(convertPathData.active).to.equal(true);
});

it('cleanupNumericValues plugin should have floatPrecision set from parameters', function () {
it('plugins should inherit floatPrecision top level config', function () {
expect(cleanupNumericValues.params.floatPrecision).to.be.equal(2);
expect(convertPathData.params.floatPrecision).to.be.equal(2);
expect(customPlugin.params.floatPrecision).to.be.equal(2);
});
});

Expand Down

0 comments on commit d58a7e6

Please sign in to comment.