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
Showing
4 changed files
with
72 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
const FS = require('fs'); | ||
const PATH = require('path'); | ||
const EOL = require('os').EOL; | ||
const regEOL = new RegExp(EOL, 'g'); | ||
const { optimize } = require('../../lib/svgo.js'); | ||
|
||
describe('indentation', function() { | ||
|
||
it('should create indent with 2 spaces', function(done) { | ||
|
||
var filepath = PATH.resolve(__dirname, './test.svg'), | ||
svgo; | ||
|
||
FS.readFile(filepath, 'utf8', function(err, data) { | ||
if (err) { | ||
throw err; | ||
} | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { EOL } = require('os'); | ||
const { optimize, extendDefaultPlugins } = require('../../lib/svgo.js'); | ||
|
||
var splitted = normalize(data).split(/\s*@@@\s*/), | ||
orig = splitted[0], | ||
should = splitted[1]; | ||
|
||
const result = optimize(orig, { | ||
path: filepath, | ||
plugins : [], | ||
js2svg : { pretty: true, indent: 2 } | ||
}); | ||
expect(normalize(result.data)).to.equal(should); | ||
done(); | ||
|
||
}); | ||
|
||
}); | ||
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); | ||
}); | ||
}); | ||
|
||
function normalize(file) { | ||
return file.trim().replace(regEOL, '\n'); | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.