From 40384ef82af7b53b011d496f047a730407ec6cf9 Mon Sep 17 00:00:00 2001 From: strarsis Date: Wed, 30 Oct 2019 02:15:03 +0100 Subject: [PATCH 01/14] Add tests for multipass. Fix multipassCounter code to make failed multipass tests pass. --- lib/svgo.js | 3 +- test/coa/_index.js | 53 +++++++++++++++++++++++++++------- test/coa/testMultipass/in.svg | 14 +++++++++ test/coa/testMultipass/out.svg | 1 + 4 files changed, 58 insertions(+), 13 deletions(-) mode change 100755 => 100644 lib/svgo.js create mode 100644 test/coa/testMultipass/in.svg create mode 100644 test/coa/testMultipass/out.svg diff --git a/lib/svgo.js b/lib/svgo.js old mode 100755 new mode 100644 index cd1569fdb..d6ff5e1bc --- a/lib/svgo.js +++ b/lib/svgo.js @@ -39,8 +39,7 @@ SVGO.prototype.optimize = function(svgstr, info) { return; } - info.multipassCount = counter; - if (++counter < maxPassCount && svgjs.data.length < prevResultSize) { + if (info.multipassCount = ++counter < maxPassCount && svgjs.data.length < prevResultSize) { prevResultSize = svgjs.data.length; this._optimizeOnce(svgjs.data, info, optimizeOnceCallback); } else { diff --git a/test/coa/_index.js b/test/coa/_index.js index ada38de1d..3d0fc2aa7 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -1,12 +1,18 @@ 'use strict'; const fs = require('fs'), + yaml = require('js-yaml'), svgo = require(process.env.COVERAGE ? '../../lib-cov/svgo/coa.js' : '../../lib/svgo/coa.js').api, + defaults = Object.assign({}, yaml.safeLoad(fs.readFileSync(__dirname + '/../../.svgo.yml', 'utf8'))), path = require('path'), svgPath = path.resolve(__dirname, 'test.svg'), svgFolderPath = path.resolve(__dirname, 'testSvg'), + mpDirPath = path.resolve(__dirname, 'testMultipass'), + mpSvgInPath = path.resolve(mpDirPath, 'in.svg'), + mpSvgExpPath = path.resolve(mpDirPath, 'out.svg'), + mpSvgExp = fs.readFileSync(mpSvgExpPath, 'utf8'), svgFolderPathRecursively = path.resolve(__dirname, 'testSvgRecursively'), svgFiles = [path.resolve(__dirname, 'testSvg/test.svg'), path.resolve(__dirname, 'testSvg/test.1.svg')], tempFolder = 'temp', @@ -157,6 +163,42 @@ describe('coa', function() { } }); + describe('multipass', function() { + it('should do multiple passes with multipass enabled', function(done) { + + svgo({ + input: mpSvgInPath, + output: 'temp.svg', + quiet: true, + multipass: true + }).then(function() { + const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); + + done(mpSvgOut === mpSvgExp ? null : "Multipass wasn't properly used."); + fse.removeSync('temp.svg'); + }, error => done(error)); + }); + + it('multipass-aware plugins (prefixIds) should detect subsequent passes with multipass enabled', function(done) { + + let pluginsExceptPrefixIds = defaults.plugins; + + svgo({ + input: mpSvgInPath, + output: 'temp.svg', + quiet: true, + multipass: true, + disable: defaults.plugins, // disable all plugins + enable: [ 'prefixIds' ] // except multipass-aware plugins (prefixIds) + }).then(function() { + const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); + + done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : "Plugins (prefixIds) don't handle multipass correctly."); + fse.removeSync('temp.svg'); + }, error => done(error)); + }); + }); + describe('stdout', function() { it('should show file content when no output set', function(done) { replaceConsoleLog(); @@ -197,16 +239,5 @@ describe('coa', function() { 'Error "No SVG files have been found" was not shown'); } }); - - it('should show plugins', function(done) { - replaceConsoleLog(); - - svgo({ 'show-plugins': true }).then(onComplete, onComplete); - - function onComplete() { - restoreConsoleLog(); - done(/Currently available plugins:/.test(output) ? null : 'List of plugins was not shown'); - } - }); }); }); diff --git a/test/coa/testMultipass/in.svg b/test/coa/testMultipass/in.svg new file mode 100644 index 000000000..e4426ec7f --- /dev/null +++ b/test/coa/testMultipass/in.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/coa/testMultipass/out.svg b/test/coa/testMultipass/out.svg new file mode 100644 index 000000000..36dc90338 --- /dev/null +++ b/test/coa/testMultipass/out.svg @@ -0,0 +1 @@ + \ No newline at end of file From 3623fdd85719c060eb9b0bf213ad1dc43260c157 Mon Sep 17 00:00:00 2001 From: strarsis Date: Wed, 30 Oct 2019 03:54:39 +0100 Subject: [PATCH 02/14] Add more tests for multipass. Improve multipass related tests. --- test/coa/_index.js | 55 +++++++++++++++++++++++++++++++---- test/coa/testPrefixIds/in.svg | 3 ++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 test/coa/testPrefixIds/in.svg diff --git a/test/coa/_index.js b/test/coa/_index.js index 3d0fc2aa7..7e4029718 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -9,10 +9,15 @@ const fs = require('fs'), path = require('path'), svgPath = path.resolve(__dirname, 'test.svg'), svgFolderPath = path.resolve(__dirname, 'testSvg'), + + prefixIdsFolderPath = path.resolve(__dirname, 'testPrefixIds'), + prefixIdsSvgInPath = path.resolve(prefixIdsFolderPath, 'in.svg'), + mpDirPath = path.resolve(__dirname, 'testMultipass'), mpSvgInPath = path.resolve(mpDirPath, 'in.svg'), mpSvgExpPath = path.resolve(mpDirPath, 'out.svg'), mpSvgExp = fs.readFileSync(mpSvgExpPath, 'utf8'), + svgFolderPathRecursively = path.resolve(__dirname, 'testSvgRecursively'), svgFiles = [path.resolve(__dirname, 'testSvg/test.svg'), path.resolve(__dirname, 'testSvg/test.1.svg')], tempFolder = 'temp', @@ -163,8 +168,24 @@ describe('coa', function() { } }); + it('should pass the filename to the prefixIds plugin', function(done) { + svgo({ + input: prefixIdsSvgInPath, + output: 'temp.svg', + quiet: true, + multipass: false, + disable: defaults.plugins, // disable all plugins except ... + enable: [ 'prefixIds' ] // ... prefixIds + }).then(function() { + const svgOut = fs.readFileSync('temp.svg', 'utf8'); + + done(/in_svg__/.test(svgOut) ? null : "filename isn't passed to prefixIds plugin."); + fse.removeSync('temp.svg'); + }, error => done(error)); + }); + describe('multipass', function() { - it('should do multiple passes with multipass enabled', function(done) { + it('should optimize using multiple passes with multipass enabled', function(done) { svgo({ input: mpSvgInPath, @@ -179,21 +200,43 @@ describe('coa', function() { }, error => done(error)); }); - it('multipass-aware plugins (prefixIds) should detect subsequent passes with multipass enabled', function(done) { + it('should allow prefixId plugin to detect subsequent passes with multipass enabled', function(done) { + svgo({ + input: mpSvgInPath, + output: 'temp.svg', + quiet: true, + multipass: true, + disable: defaults.plugins, // disable all plugins except ... + enable: [ 'prefixIds' ] // ... prefixIds + }).then(function() { + const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); - let pluginsExceptPrefixIds = defaults.plugins; + done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : "prefixIds plugin doesn't detect subsequent passes with multipass enabled."); + // https://github.com/svg/svgo/issues/659 + // https://github.com/svg/svgo/issues/1133 + fse.removeSync('temp.svg'); + }, error => done(error)); + }); + + it('should allow addAttributesToSVGElement plugin to correctly handle subsequent passes with multipass enabled', function(done) { svgo({ input: mpSvgInPath, output: 'temp.svg', quiet: true, multipass: true, - disable: defaults.plugins, // disable all plugins - enable: [ 'prefixIds' ] // except multipass-aware plugins (prefixIds) + config: `{ + "plugins": [{ "addAttributesToSVGElement": { + "attribute": "aria-hidden='true'" + } }] + }` }).then(function() { const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); - done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : "Plugins (prefixIds) don't handle multipass correctly."); + done(!/aria-hidden="true" aria-hidden='true'/.test(mpSvgOut) ? null : "addAttributesToSVGElement plugin doesn't correctly handle subsequent passes with multipass enabled."); + + // https://github.com/svg/svgo/issues/659 + // https://github.com/svg/svgo/issues/1133 fse.removeSync('temp.svg'); }, error => done(error)); }); diff --git a/test/coa/testPrefixIds/in.svg b/test/coa/testPrefixIds/in.svg new file mode 100644 index 000000000..fe1b3c6dc --- /dev/null +++ b/test/coa/testPrefixIds/in.svg @@ -0,0 +1,3 @@ + + + From 3916f93513c34d65e6d841bf68e9197eb4ef4f37 Mon Sep 17 00:00:00 2001 From: strarsis Date: Wed, 30 Oct 2019 19:21:53 +0100 Subject: [PATCH 03/14] Fkx quotes in addAttributesToSVGElement plugin config. --- test/coa/_index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/coa/_index.js b/test/coa/_index.js index 7e4029718..7935be0fb 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -227,7 +227,7 @@ describe('coa', function() { multipass: true, config: `{ "plugins": [{ "addAttributesToSVGElement": { - "attribute": "aria-hidden='true'" + "attribute": "aria-hidden=\\"true\\"" } }] }` }).then(function() { From d1274df6f35524ab2f9fc7507ec9631d20b1dd19 Mon Sep 17 00:00:00 2001 From: strarsis Date: Wed, 30 Oct 2019 19:27:05 +0100 Subject: [PATCH 04/14] Fix lint errors. --- lib/svgo.js | 2 +- test/coa/_index.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/svgo.js b/lib/svgo.js index d6ff5e1bc..3f5f7dd24 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -39,7 +39,7 @@ SVGO.prototype.optimize = function(svgstr, info) { return; } - if (info.multipassCount = ++counter < maxPassCount && svgjs.data.length < prevResultSize) { + if ((info.multipassCount = ++counter) < maxPassCount && svgjs.data.length < prevResultSize) { prevResultSize = svgjs.data.length; this._optimizeOnce(svgjs.data, info, optimizeOnceCallback); } else { diff --git a/test/coa/_index.js b/test/coa/_index.js index 7935be0fb..b6ac707c8 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -179,7 +179,7 @@ describe('coa', function() { }).then(function() { const svgOut = fs.readFileSync('temp.svg', 'utf8'); - done(/in_svg__/.test(svgOut) ? null : "filename isn't passed to prefixIds plugin."); + done(/in_svg__/.test(svgOut) ? null : 'filename isn\'t passed to prefixIds plugin.'); fse.removeSync('temp.svg'); }, error => done(error)); }); @@ -195,7 +195,7 @@ describe('coa', function() { }).then(function() { const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); - done(mpSvgOut === mpSvgExp ? null : "Multipass wasn't properly used."); + done(mpSvgOut === mpSvgExp ? null : 'Multipass wasn\'t properly used.'); fse.removeSync('temp.svg'); }, error => done(error)); }); @@ -211,7 +211,7 @@ describe('coa', function() { }).then(function() { const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); - done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : "prefixIds plugin doesn't detect subsequent passes with multipass enabled."); + done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : 'prefixIds plugin doesn\'t detect subsequent passes with multipass enabled.'); // https://github.com/svg/svgo/issues/659 // https://github.com/svg/svgo/issues/1133 @@ -233,7 +233,7 @@ describe('coa', function() { }).then(function() { const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); - done(!/aria-hidden="true" aria-hidden='true'/.test(mpSvgOut) ? null : "addAttributesToSVGElement plugin doesn't correctly handle subsequent passes with multipass enabled."); + done(!/aria-hidden="true" aria-hidden='true'/.test(mpSvgOut) ? null : 'addAttributesToSVGElement plugin doesn\'t correctly handle subsequent passes with multipass enabled.'); // https://github.com/svg/svgo/issues/659 // https://github.com/svg/svgo/issues/1133 From 26e66ed81286c48bc9afafa07d7d02a2131c50b0 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Thu, 31 Oct 2019 07:34:35 +0100 Subject: [PATCH 05/14] Change wording of API doc comment --- lib/svgo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svgo.js b/lib/svgo.js index 3f5f7dd24..ae759728e 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -75,7 +75,7 @@ SVGO.prototype._optimizeOnce = function(svgstr, info, callback) { /** * The factory that creates a content item with the helper methods. * - * @param {Object} data which passed to jsAPI constructor + * @param {Object} data which is passed to jsAPI constructor * @returns {JSAPI} content item */ SVGO.prototype.createContentItem = function(data) { From aef98253976c2233fd0a4af2b24aca41e9acab28 Mon Sep 17 00:00:00 2001 From: jlherren Date: Tue, 5 Nov 2019 16:41:02 +0100 Subject: [PATCH 06/14] Fix collapsing of repeated commands in convertPathData plugin This fixes #1166 --- plugins/convertPathData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js index e0bcf8dad..986381b81 100644 --- a/plugins/convertPathData.js +++ b/plugins/convertPathData.js @@ -514,7 +514,7 @@ function filters(path, params) { instruction == prev.instruction.toLowerCase() && ( (instruction != 'h' && instruction != 'v') || - (prev.data[0] >= 0) == (item.data[0] >= 0) + (prev.data[0] >= 0) == (data[0] >= 0) )) { prev.data[0] += data[0]; if (instruction != 'h' && instruction != 'v') { From f35e6715dd6b3dfb9cd885051cf03b475c6d3a33 Mon Sep 17 00:00:00 2001 From: GreLI Date: Tue, 5 Nov 2019 19:32:02 +0300 Subject: [PATCH 07/14] Add test for collapsing of repeated commands --- test/plugins/convertPathData.04.svg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/plugins/convertPathData.04.svg b/test/plugins/convertPathData.04.svg index 0dae5fde3..c169d833a 100644 --- a/test/plugins/convertPathData.04.svg +++ b/test/plugins/convertPathData.04.svg @@ -5,6 +5,7 @@ + @@@ @@ -16,4 +17,5 @@ + From 7ef64b01710c863c88336e4b1b52b53c9d4d1dfe Mon Sep 17 00:00:00 2001 From: Sviatoslav Bulbakha Date: Fri, 8 Nov 2019 18:36:45 +0300 Subject: [PATCH 08/14] Fix `prefixIds` plugin error with animations Fix #848 --- plugins/prefixIds.js | 31 +++++++++++++++++++++++++++++++ test/plugins/prefixIds.10.svg | 15 +++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/plugins/prefixIds.10.svg diff --git a/plugins/prefixIds.js b/plugins/prefixIds.js index 2222e7eb6..9aff8bf90 100755 --- a/plugins/prefixIds.js +++ b/plugins/prefixIds.js @@ -113,6 +113,35 @@ var addPrefixToUrlAttr = function(attr) { attr.value = 'url(' + idPrefixed + ')'; }; +// prefixes begin/end attribute value +var addPrefixToBeginEndAttr = function(attr) { + if (!attrNotEmpty(attr)) { + return; + } + + var parts = attr.value.split('; ').map(function(val) { + val = val.trim(); + + if (val.endsWith('.end') || val.endsWith('.start')) { + var idPostfix = val.split('.'), + id = idPostfix[0], + postfix = idPostfix[1]; + + var idPrefixed = prefixId(`#${id}`); + + if (!idPrefixed) { + return val; + } + + idPrefixed = idPrefixed.slice(1); + return `${idPrefixed}.${postfix}`; + } else { + return val; + } + }); + + attr.value = parts.join('; '); +}; /** * Prefixes identifiers @@ -238,6 +267,8 @@ exports.fn = function(node, opts, extra) { addPrefixToUrlAttr(node.attrs[referencesProp]); } + addPrefixToBeginEndAttr(node.attrs.begin); + addPrefixToBeginEndAttr(node.attrs.end); return node; }; diff --git a/test/plugins/prefixIds.10.svg b/test/plugins/prefixIds.10.svg new file mode 100644 index 000000000..2013210d1 --- /dev/null +++ b/test/plugins/prefixIds.10.svg @@ -0,0 +1,15 @@ + + + + + + + +@@@ + + + + + + + From 3934775266402f3e1d5013e34ea4b90244125247 Mon Sep 17 00:00:00 2001 From: GreLI Date: Fri, 8 Nov 2019 18:40:25 +0300 Subject: [PATCH 09/14] Correct test --- test/plugins/prefixIds.10.svg | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/plugins/prefixIds.10.svg b/test/plugins/prefixIds.10.svg index 2013210d1..7b4ce3188 100644 --- a/test/plugins/prefixIds.10.svg +++ b/test/plugins/prefixIds.10.svg @@ -1,15 +1,15 @@ - - - - + + + + @@@ - - - + + + From d759f460cfd818451550c18112140f47b5548ff3 Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Fri, 8 Nov 2019 20:58:43 +0100 Subject: [PATCH 10/14] Perform `cleanupIDs` optimization when style/script tag is empty cleanupIDs plugin is disabled when a script or style tag is present. I assume that this is because they might contain an id. If these tags are empty there is no point in not cleaning the id though. When running svgo with the option `multipass: true`, it allows us to first run `inlineStyles` plugin to empty the style tag. Then, we can run `cleanupIDs` plugin. --- plugins/cleanupIDs.js | 3 ++- test/plugins/cleanupIDs.02.svg | 4 ++-- test/plugins/cleanupIDs.19.svg | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/plugins/cleanupIDs.19.svg diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 918474a04..aebec0510 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -58,7 +58,8 @@ exports.fn = function(data, params) { // quit if @@ -9,7 +9,7 @@ diff --git a/test/plugins/cleanupIDs.19.svg b/test/plugins/cleanupIDs.19.svg new file mode 100644 index 000000000..b961e21bf --- /dev/null +++ b/test/plugins/cleanupIDs.19.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + +@@@ + + + + + + + + + + + From 9cf1f38ae3c030ddf4b4b4215af144597314a10c Mon Sep 17 00:00:00 2001 From: alexpavlovich Date: Sat, 9 Nov 2019 21:41:17 +0300 Subject: [PATCH 11/14] Fix cleanupIDs if defs is last elem of svg --- plugins/cleanupIDs.js | 8 ++++--- test/plugins/cleanupIDs.20.svg | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/plugins/cleanupIDs.20.svg diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index aebec0510..71ffb5f93 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -63,11 +63,13 @@ exports.fn = function(data, params) { hasStyleOrScript = true; continue; } + // Don't remove IDs if the whole SVG consists only of defs. - if (item.isElem('defs') && item.parentNode.isElem('svg')) { + if (item.isElem('svg')) { var hasDefsOnly = true; - for (var j = i + 1; j < items.content.length; j++) { - if (items.content[j].isElem()) { + + for (var j = 0; j < item.content.length; j++) { + if (!item.content[j].isElem('defs')) { hasDefsOnly = false; break; } diff --git a/test/plugins/cleanupIDs.20.svg b/test/plugins/cleanupIDs.20.svg new file mode 100644 index 000000000..2fa086946 --- /dev/null +++ b/test/plugins/cleanupIDs.20.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + + + + + + +@@@ + +{"prefix": "test__", "remove": "false"} From ba478795a03691664c3e2a652b711930c0da119b Mon Sep 17 00:00:00 2001 From: Eugene Chechuryn Date: Mon, 9 Dec 2019 22:15:47 +0200 Subject: [PATCH 12/14] Add Figma plugin link to Readme --- README.md | 1 + README.ru.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 3b676e0ba..bce6c91a4 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ Arguments: * as a Sketch plugin - [svgo-compressor](https://github.com/BohemianCoding/svgo-compressor) * as macOS app - [Image Shrinker](https://image-shrinker.com) * as a Rollup plugin - [rollup-plugin-svgo](https://github.com/porsager/rollup-plugin-svgo) +* as a Figma plugin - [Advanced SVG Export](https://www.figma.com/c/plugin/782713260363070260/Advanced-SVG-Export) ## Backers diff --git a/README.ru.md b/README.ru.md index 319e963ce..61fe57e21 100644 --- a/README.ru.md +++ b/README.ru.md @@ -197,6 +197,7 @@ $ [sudo] npm install -g svgo * как плагин для Sketch - [svgo-compressor](https://github.com/BohemianCoding/svgo-compressor) * в виде приложения macOS - [Image Shrinker](https://image-shrinker.com) * как плагин для Rollup - [rollup-plugin-svgo](https://github.com/porsager/rollup-plugin-svgo) +* как плагин для Figma - [Advanced SVG Export](https://www.figma.com/c/plugin/782713260363070260/Advanced-SVG-Export) ## Лицензия и копирайты From 81f87616c85494cc6b4bc4c02b088b83a37ddda8 Mon Sep 17 00:00:00 2001 From: strarsis Date: Mon, 9 Mar 2020 15:33:36 +0100 Subject: [PATCH 13/14] Remove unrelated comments. --- test/coa/_index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/coa/_index.js b/test/coa/_index.js index b6ac707c8..0f17d9cc3 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -213,8 +213,6 @@ describe('coa', function() { done(!/in_svg__in_svg__/.test(mpSvgOut) ? null : 'prefixIds plugin doesn\'t detect subsequent passes with multipass enabled.'); - // https://github.com/svg/svgo/issues/659 - // https://github.com/svg/svgo/issues/1133 fse.removeSync('temp.svg'); }, error => done(error)); }); From fb4dd6b018c01466c41b28d319937e8b420aaa00 Mon Sep 17 00:00:00 2001 From: strarsis Date: Mon, 9 Mar 2020 15:56:39 +0100 Subject: [PATCH 14/14] Add test for specific config set for prefixIds with multipass. --- test/coa/_index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/coa/_index.js b/test/coa/_index.js index 0f17d9cc3..adfa53e64 100644 --- a/test/coa/_index.js +++ b/test/coa/_index.js @@ -217,6 +217,22 @@ describe('coa', function() { }, error => done(error)); }); + it('should work correctly with some specific options', function(done) { + svgo({ + input: mpSvgInPath, + output: 'temp.svg', + quiet: true, + multipass: true, + config: '{ "plugins": [ { "prefixIds": { "delim": "_" } }, { "cleanupIDs": { "minify": true } } ] }', + }).then(function() { + const mpSvgOut = fs.readFileSync('temp.svg', 'utf8'); + + done(/in_svg_/.test(mpSvgOut) ? null : 'prefixIds plugin doesn\'t work correctly with some specific options.'); + + fse.removeSync('temp.svg'); + }, error => done(error)); + }); + it('should allow addAttributesToSVGElement plugin to correctly handle subsequent passes with multipass enabled', function(done) { svgo({ input: mpSvgInPath,