-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cfaa27
commit 961fba3
Showing
5 changed files
with
2,098 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/icons-scripts/scripts/plugins/tests/_index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use strict"; | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
const EOL = require("os").EOL; | ||
const regEOL = new RegExp(EOL, "g"); | ||
const regFilename = /^(.*)\.(\d+)\.svg$/; | ||
const { optimize } = require("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 () { | ||
return readFile(file).then(function (data) { | ||
// remove description | ||
const items = normalize(data).split(/\s*===\s*/); | ||
const test = items.length === 2 ? items[1] : items[0]; | ||
|
||
// extract test case | ||
const [original, should, params] = test.split(/\s*@@@\s*/); | ||
const plugin = { | ||
params: params ? JSON.parse(params) : {}, | ||
...require("../" + name), | ||
}; | ||
|
||
const result = optimize(original, { | ||
path: file, | ||
plugins: [plugin], | ||
js2svg: { pretty: true }, | ||
}); | ||
|
||
expect(result.error).not.toEqual(expect.anything()); | ||
expect(normalize(result.data)).toEqual(should); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
function normalize(file) { | ||
return file.trim().replace(regEOL, "\n"); | ||
} | ||
|
||
function readFile(file) { | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(file, "utf8", function (err, data) { | ||
if (err) return reject(err); | ||
resolve(data); | ||
}); | ||
}); | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/icons-scripts/scripts/plugins/tests/removeTransparentPaths.01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.