Skip to content

Commit f2b2367

Browse files
authoredMar 22, 2020
fix(svgo): support any SVGO config format (#412)
Fixes #400
1 parent 853db4e commit f2b2367

File tree

5 files changed

+215
-68
lines changed

5 files changed

+215
-68
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`svgo should be possible to disable id prefixing 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"Blocks\\" class=\\"blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
3+
exports[`svgo disables id prefixing using svgo config 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"Blocks\\" class=\\"blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
44
5-
exports[`svgo should not load runtime configuration with \`runtimeConfig: false\` 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
5+
exports[`svgo does not load runtime configuration with \`runtimeConfig: false\` 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
66
7-
exports[`svgo should not remove viewBox with icon option 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
7+
exports[`svgo does not remove viewBox with \`icon\` option 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
88
9-
exports[`svgo should not remove viewBox with when dimensions is false 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
9+
exports[`svgo does not remove viewBox with when \`dimensions\` is false 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
1010
11-
exports[`svgo should optimize svg 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
11+
exports[`svgo is possible to enable id prefixing as the only optimization 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><svg width=\\"88px\\" height=\\"88px\\" viewBox=\\"0 0 88 88\\" version=\\"1.1\\" xmlns=\\"http://www.w3.org/2000/svg\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\"><!--Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch--><title>Dismiss</title><desc>Created with Sketch.</desc><defs/><g id=\\"svgo__Blocks\\" class=\\"blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51,37 L37,51\\" id=\\"svgo__Shape\\"/><path d=\\"M51,51 L37,37\\" id=\\"svgo__Shape\\"/><style>#svgo__Shape{}</style></g></g></svg>"`;
1212
13-
exports[`svgo should support config.svgoConfig 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><desc>Created with Sketch.</desc><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
13+
exports[`svgo optimizes svg 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
1414
15-
exports[`svgo should support icon with config.svgoConfig plugins 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><desc>Created with Sketch.</desc><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
15+
exports[`svgo supports \`config.icon\` with \`config.svgoConfig\` plugins 1`] = `"<svg width=\\"88\\" height=\\"88\\" viewBox=\\"0 0 88 88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><desc>Created with Sketch.</desc><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
1616
17-
exports[`svgo should use state.filePath to detect configuration 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
17+
exports[`svgo supports \`config.svgoConfig.multipass\` 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"prefix__prefix__Blocks\\" class=\\"prefix__prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style/></g></g></svg>"`;
1818
19-
exports[`svgo should be possible to enable id prefixing as the only optimization 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><svg width=\\"88px\\" height=\\"88px\\" viewBox=\\"0 0 88 88\\" version=\\"1.1\\" xmlns=\\"http://www.w3.org/2000/svg\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\"><!--Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch--><title>Dismiss</title><desc>Created with Sketch.</desc><defs/><g id=\\"svgo__Blocks\\" class=\\"blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51,37 L37,51\\" id=\\"svgo__Shape\\"/><path d=\\"M51,51 L37,37\\" id=\\"svgo__Shape\\"/><style>#svgo__Shape{}</style></g></g></svg>"`;
19+
exports[`svgo supports \`config.svgoConfig\` 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><desc>Created with Sketch.</desc><g id=\\"prefix__Blocks\\" class=\\"prefix__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;
20+
21+
exports[`svgo users \`state.filePath\` to detect configuration 1`] = `"<svg width=\\"88\\" height=\\"88\\" xmlns=\\"http://www.w3.org/2000/svg\\"><g id=\\"svgo__Blocks\\" class=\\"svgo__blocks\\" stroke=\\"none\\" stroke-width=\\"1\\" fill=\\"none\\" fill-rule=\\"evenodd\\" stroke-linecap=\\"square\\"><g id=\\"svgo__Dismiss\\" stroke=\\"#063855\\" stroke-width=\\"2\\"><path d=\\"M51 37L37 51\\" id=\\"svgo__Shape\\"/><path d=\\"M51 51L37 37\\"/><style></style></g></g></svg>"`;

‎packages/plugin-svgo/src/config.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import mergeDeep from 'merge-deep'
2+
3+
export function getFilePath(state) {
4+
return state.filePath || process.cwd()
5+
}
6+
7+
export function getBaseSvgoConfig(config) {
8+
const baseSvgoConfig = {
9+
plugins: [{ prefixIds: true }],
10+
}
11+
if (config.icon || config.dimensions === false) {
12+
baseSvgoConfig.plugins.push({ removeViewBox: false })
13+
}
14+
return baseSvgoConfig
15+
}
16+
17+
export function getPlugins(config) {
18+
if (!config || !config.plugins) {
19+
return []
20+
}
21+
if (!Array.isArray(config.plugins)) {
22+
throw Error('`svgoConfig.plugins` must be an array')
23+
}
24+
return config.plugins
25+
}
26+
27+
function extractPlugins(config) {
28+
if (!config) return []
29+
if (!config.plugins) return []
30+
if (!Array.isArray(config.plugins)) return [config.plugins]
31+
return config.plugins
32+
}
33+
34+
function mergePlugins(configs) {
35+
const plugins = configs.reduce(
36+
(merged, config) => mergeDeep(merged, ...extractPlugins(config)),
37+
{},
38+
)
39+
return Object.keys(plugins).reduce((array, key) => {
40+
array.push({ [key]: plugins[key] })
41+
return array
42+
}, [])
43+
}
44+
45+
export function mergeSvgoConfig(...configs) {
46+
const plugins = mergePlugins(configs)
47+
return { ...mergeDeep(...configs), plugins }
48+
}
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { getFilePath, getBaseSvgoConfig, mergeSvgoConfig } from './config'
2+
3+
describe('svgo config', () => {
4+
describe('#getFilePath', () => {
5+
describe('if `state.filePath` exists', () => {
6+
it('returns `state.filePath', () => {
7+
expect(getFilePath({ filePath: '/foo/bar' })).toBe('/foo/bar')
8+
})
9+
})
10+
describe('if `state.filePath` does not exists', () => {
11+
it('returns current working directory', () => {
12+
expect(getFilePath({})).toBe(process.cwd())
13+
})
14+
})
15+
})
16+
17+
describe('#getBaseSvgoConfig', () => {
18+
describe('with no specific config', () => {
19+
it('returns config with `prefixIds: true`', () => {
20+
expect(getBaseSvgoConfig({})).toEqual({
21+
plugins: [{ prefixIds: true }],
22+
})
23+
})
24+
})
25+
26+
describe('with `config.icons` enabled', () => {
27+
it('returns config with `removeViewBox: false`', () => {
28+
expect(getBaseSvgoConfig({ icon: true })).toEqual({
29+
plugins: [{ prefixIds: true }, { removeViewBox: false }],
30+
})
31+
})
32+
})
33+
34+
describe('with `config.dimensions` disabled', () => {
35+
it('returns config with `removeViewBox: false`', () => {
36+
expect(getBaseSvgoConfig({ dimensions: false })).toEqual({
37+
plugins: [{ prefixIds: true }, { removeViewBox: false }],
38+
})
39+
})
40+
})
41+
})
42+
43+
describe('#mergeSvgoConfig', () => {
44+
it('merges any config format', () => {
45+
expect(mergeSvgoConfig({ foo: 'bar' }, { foo: 'rab' })).toEqual({
46+
foo: 'rab',
47+
plugins: [],
48+
})
49+
expect(
50+
mergeSvgoConfig({ plugins: { removeViewBox: false } }, null),
51+
).toEqual({
52+
plugins: [{ removeViewBox: false }],
53+
})
54+
expect(
55+
mergeSvgoConfig({ plugins: { removeViewBox: false } }, {}),
56+
).toEqual({
57+
plugins: [{ removeViewBox: false }],
58+
})
59+
expect(mergeSvgoConfig({ plugins: { removeViewBox: false } })).toEqual({
60+
plugins: [{ removeViewBox: false }],
61+
})
62+
expect(mergeSvgoConfig({ plugins: [{ removeViewBox: false }] })).toEqual({
63+
plugins: [{ removeViewBox: false }],
64+
})
65+
expect(
66+
mergeSvgoConfig({
67+
plugins: [{ removeViewBox: false }, { removeViewBox: true }],
68+
}),
69+
).toEqual({
70+
plugins: [{ removeViewBox: true }],
71+
})
72+
expect(
73+
mergeSvgoConfig({
74+
plugins: [
75+
{
76+
convertColors: {
77+
currentColor: true,
78+
},
79+
},
80+
{
81+
prefixIds: {
82+
prefix: 'foo',
83+
},
84+
},
85+
],
86+
}),
87+
).toEqual({
88+
plugins: [
89+
{
90+
convertColors: {
91+
currentColor: true,
92+
},
93+
},
94+
{
95+
prefixIds: {
96+
prefix: 'foo',
97+
},
98+
},
99+
],
100+
})
101+
expect(
102+
mergeSvgoConfig(
103+
{
104+
plugins: [
105+
{
106+
prefixIds: {
107+
prefix: 'foo',
108+
},
109+
},
110+
],
111+
},
112+
{
113+
plugins: [
114+
{
115+
prefixIds: {
116+
prefix: 'bar',
117+
},
118+
},
119+
],
120+
},
121+
),
122+
).toEqual({
123+
plugins: [
124+
{
125+
prefixIds: {
126+
prefix: 'bar',
127+
},
128+
},
129+
],
130+
})
131+
})
132+
})
133+
})

‎packages/plugin-svgo/src/index.js

+3-44
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-underscore-dangle */
22
import SVGO from 'svgo'
33
import { cosmiconfigSync } from 'cosmiconfig'
4-
import mergeDeep from 'merge-deep'
4+
import { getFilePath, getBaseSvgoConfig, mergeSvgoConfig } from './config'
55

66
const explorer = cosmiconfigSync('svgo', {
77
searchPlaces: [
@@ -83,54 +83,13 @@ function optimizeSync(svgstr, info) {
8383
return result
8484
}
8585

86-
function getBaseSvgoConfig(config) {
87-
const baseSvgoConfig = {
88-
plugins: [{ prefixIds: true }],
89-
}
90-
if (config.icon || config.dimensions === false)
91-
baseSvgoConfig.plugins.push({ removeViewBox: false })
92-
return baseSvgoConfig
93-
}
94-
95-
function getFilePath(state) {
96-
return state.filePath || process.cwd()
97-
}
98-
99-
function getPlugins(config) {
100-
if (!config || !config.plugins) {
101-
return []
102-
}
103-
if (!Array.isArray(config.plugins)) {
104-
throw Error("`svgoConfig.plugins` must be an array")
105-
}
106-
return config.plugins
107-
}
108-
109-
function extendPlugins(...configs) {
110-
const init = [];
111-
let i = configs.length;
112-
113-
while (i-- > 0) {
114-
const plugins = configs[i];
115-
for (let j = 0; j < plugins.length; j++) {
116-
const plugin = plugins[j];
117-
if (!init.some(item => Object.keys(item)[0] === Object.keys(plugin)[0])) {
118-
init.push(plugin);
119-
}
120-
}
121-
}
122-
return init;
123-
}
124-
12586
function createSvgo(config, rcConfig) {
126-
const baseSvgoConfig = getBaseSvgoConfig(config);
127-
const plugins = extendPlugins(getPlugins(baseSvgoConfig), getPlugins(rcConfig), getPlugins(config.svgoConfig));
128-
const mergedConfig = mergeDeep(
87+
const baseSvgoConfig = getBaseSvgoConfig(config)
88+
const mergedConfig = mergeSvgoConfig(
12989
baseSvgoConfig,
13090
rcConfig,
13191
config.svgoConfig,
13292
)
133-
mergedConfig.plugins = plugins
13493
return new SVGO(mergedConfig)
13594
}
13695

‎packages/plugin-svgo/src/index.test.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const baseSvg = `<?xml version="1.0" encoding="UTF-8"?>
1919
</svg>`
2020

2121
describe('svgo', () => {
22-
it('should optimize svg', () => {
22+
it('optimizes svg', () => {
2323
const result = svgo(baseSvg, { svgo: true, runtimeConfig: true }, {})
2424
expect(result).toMatchSnapshot()
2525
})
2626

27-
it('should support config.svgoConfig', () => {
27+
it('supports `config.svgoConfig`', () => {
2828
const result = svgo(
2929
baseSvg,
3030
{
@@ -38,21 +38,21 @@ describe('svgo', () => {
3838
expect(result).toMatchSnapshot()
3939
})
4040

41-
it('should throw error for invalid config.svgoConfig', () => {
42-
const svgoOptions = [
41+
it('supports `config.svgoConfig.multipass`', () => {
42+
const result = svgo(
4343
baseSvg,
4444
{
4545
svgo: true,
4646
runtimeConfig: true,
47-
svgoConfig: { plugins: { removeDesc: false } },
47+
svgoConfig: { multipass: true },
4848
},
4949
{},
50-
]
50+
)
5151

52-
expect(() => svgo(...svgoOptions)).toThrow()
52+
expect(result).toMatchSnapshot()
5353
})
5454

55-
it('should support icon with config.svgoConfig plugins', () => {
55+
it('supports `config.icon` with `config.svgoConfig` plugins', () => {
5656
const result = svgo(
5757
baseSvg,
5858
{
@@ -67,7 +67,7 @@ describe('svgo', () => {
6767
expect(result).toMatchSnapshot()
6868
})
6969

70-
it('should use state.filePath to detect configuration', () => {
70+
it('users `state.filePath` to detect configuration', () => {
7171
const result = svgo(
7272
baseSvg,
7373
{ svgo: true, runtimeConfig: true },
@@ -77,7 +77,7 @@ describe('svgo', () => {
7777
expect(result).toMatchSnapshot()
7878
})
7979

80-
it('should not load runtime configuration with `runtimeConfig: false`', () => {
80+
it('does not load runtime configuration with `runtimeConfig: false`', () => {
8181
const result = svgo(
8282
baseSvg,
8383
{ svgo: true, runtimeConfig: false },
@@ -87,7 +87,7 @@ describe('svgo', () => {
8787
expect(result).toMatchSnapshot()
8888
})
8989

90-
it('should not remove viewBox with icon option', () => {
90+
it('does not remove viewBox with `icon` option', () => {
9191
const result = svgo(
9292
baseSvg,
9393
{ svgo: true, icon: true, runtimeConfig: true },
@@ -97,7 +97,7 @@ describe('svgo', () => {
9797
expect(result).toMatchSnapshot()
9898
})
9999

100-
it('should not remove viewBox with when dimensions is false', () => {
100+
it('does not remove viewBox with when `dimensions` is false', () => {
101101
const result = svgo(
102102
baseSvg,
103103
{ svgo: true, dimensions: false, runtimeConfig: true },
@@ -107,7 +107,7 @@ describe('svgo', () => {
107107
expect(result).toMatchSnapshot()
108108
})
109109

110-
it('should be possible to disable id prefixing', () => {
110+
it('disables id prefixing using svgo config', () => {
111111
const result = svgo(
112112
baseSvg,
113113
{
@@ -122,14 +122,19 @@ describe('svgo', () => {
122122
expect(result).toMatchSnapshot()
123123
})
124124

125-
it('should be possible to enable id prefixing as the only optimization', () => {
125+
it('is possible to enable id prefixing as the only optimization', () => {
126126
const result = svgo(
127127
baseSvg,
128128
{
129129
svgo: true,
130130
icon: true,
131131
runtimeConfig: true,
132-
svgoConfig: { full: true, plugins: [{ prefixIds: {prefixIds: true, prefixClassNames: false} }] },
132+
svgoConfig: {
133+
full: true,
134+
plugins: [
135+
{ prefixIds: { prefixIds: true, prefixClassNames: false } },
136+
],
137+
},
133138
},
134139
{ filePath: path.join(__dirname, '../__fixtures__/svgo') },
135140
)

1 commit comments

Comments
 (1)
Please sign in to comment.