-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_index.js
66 lines (45 loc) · 1.64 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var FS = require('fs'),
PATH = require('path'),
EOL = require('os').EOL,
regEOL = new RegExp(EOL, 'g'),
regFilename = /^(.*)\.(\d+)\.svg$/,
SVGO = require(process.env.COVERAGE ?
'../../lib-cov/svgo':
'../../lib/svgo');
describe('plugins tests', function() {
FS.readdirSync(__dirname).forEach(function(file) {
var match = file.match(regFilename),
index,
name;
if (match) {
name = match[1];
index = match[2];
file = PATH.resolve(__dirname, file);
it(name + '.' + index, function(done) {
FS.readFile(file, 'utf8', function(err, data) {
var splitted = normalize(data).split(/\s*@@@\s*/),
orig = splitted[0],
should = splitted[1],
params = splitted[2],
plugins = {},
svgo;
plugins[name] = (params) ? JSON.parse(params) : true;
svgo = new SVGO({
full : true,
plugins : [ plugins ],
js2svg : { pretty: true }
});
svgo.optimize(orig, function(result) {
//FIXME: results.data has a '\n' at the end while it should not
normalize(result.data).should.be.equal(should);
done();
});
});
});
}
});
});
function normalize(file) {
return file.trim().replace(regEOL, '\n');
}