/
_index.js
49 lines (44 loc) · 1.48 KB
/
_index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const { expect } = require('chai');
const fs = require('fs');
const path = require('path');
const { EOL } = require('os');
const { optimize, extendDefaultPlugins } = require('../../lib/svgo.js');
const regEOL = new RegExp(EOL, 'g');
const normalize = (file) => {
return file.trim().replace(regEOL, '\n');
};
const parseFixture = async file => {
const filepath = path.resolve(__dirname, file);
const content = await fs.promises.readFile(filepath, 'utf-8');
return normalize(content).split(/\s*@@@\s*/);
};
describe('svgo', () => {
it('should create indent with 2 spaces', async () => {
const [original, expected] = await parseFixture('test.svg');
const result = optimize(original, {
plugins: [],
js2svg: { pretty: true, indent: 2 },
});
expect(normalize(result.data)).to.equal(expected);
});
it('should run multiple times', async () => {
const [original, expected] = await parseFixture('multipass.svg');
const result = optimize(original, {
multipass: true,
});
expect(normalize(result.data)).to.equal(expected);
});
it('should pass multipass count to plugins', async () => {
const [original, expected] = await parseFixture('multipass-prefix-ids.svg');
const result = optimize(original, {
multipass: true,
plugins: extendDefaultPlugins([
{
name: 'prefixIds',
},
]),
});
expect(normalize(result.data)).to.equal(expected);
});
});