mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Migrate to jest (#1520)
Mocha doesn't have a lot of features provided by jest. There is a great assertion library out of the box. And the most cool feature is inline snapshots. Mocha also hides errors which makes debugging a nightmare sometimes.
This commit is contained in:
@ -1,59 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const { parsePathData, stringifyPathData } = require('./path.js');
|
||||
|
||||
describe('parse path data', () => {
|
||||
it('should allow spaces between commands', () => {
|
||||
expect(parsePathData('M0 10 L \n\r\t20 30')).to.deep.equal([
|
||||
expect(parsePathData('M0 10 L \n\r\t20 30')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
{ command: 'L', args: [20, 30] },
|
||||
]);
|
||||
});
|
||||
it('should allow spaces and commas between arguments', () => {
|
||||
expect(parsePathData('M0 , 10 L 20 \n\r\t30,40,50')).to.deep.equal([
|
||||
expect(parsePathData('M0 , 10 L 20 \n\r\t30,40,50')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
{ command: 'L', args: [20, 30] },
|
||||
{ command: 'L', args: [40, 50] },
|
||||
]);
|
||||
});
|
||||
it('should forbid commas before commands', () => {
|
||||
expect(parsePathData(', M0 10')).to.deep.equal([]);
|
||||
expect(parsePathData(', M0 10')).toEqual([]);
|
||||
});
|
||||
it('should forbid commas between commands', () => {
|
||||
expect(parsePathData('M0,10 , L 20,30')).to.deep.equal([
|
||||
expect(parsePathData('M0,10 , L 20,30')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
]);
|
||||
});
|
||||
it('should forbid commas between command name and argument', () => {
|
||||
expect(parsePathData('M0,10 L,20,30')).to.deep.equal([
|
||||
expect(parsePathData('M0,10 L,20,30')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
]);
|
||||
});
|
||||
it('should forbid multipe commas in a row', () => {
|
||||
expect(parsePathData('M0 , , 10')).to.deep.equal([]);
|
||||
expect(parsePathData('M0 , , 10')).toEqual([]);
|
||||
});
|
||||
it('should stop when unknown char appears', () => {
|
||||
expect(parsePathData('M0 10 , L 20 #40')).to.deep.equal([
|
||||
expect(parsePathData('M0 10 , L 20 #40')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
]);
|
||||
});
|
||||
it('should stop when not enough arguments', () => {
|
||||
expect(parsePathData('M0 10 L 20 L 30 40')).to.deep.equal([
|
||||
expect(parsePathData('M0 10 L 20 L 30 40')).toEqual([
|
||||
{ command: 'M', args: [0, 10] },
|
||||
]);
|
||||
});
|
||||
it('should stop if moveto not the first command', () => {
|
||||
expect(parsePathData('L 10 20')).to.deep.equal([]);
|
||||
expect(parsePathData('10 20')).to.deep.equal([]);
|
||||
expect(parsePathData('L 10 20')).toEqual([]);
|
||||
expect(parsePathData('10 20')).toEqual([]);
|
||||
});
|
||||
it('should stop on invalid scientific notation', () => {
|
||||
expect(parsePathData('M 0 5e++1 L 0 0')).to.deep.equal([
|
||||
expect(parsePathData('M 0 5e++1 L 0 0')).toEqual([
|
||||
{ command: 'M', args: [0, 5] },
|
||||
]);
|
||||
});
|
||||
it('should stop on invalid numbers', () => {
|
||||
expect(parsePathData('M ...')).to.deep.equal([]);
|
||||
expect(parsePathData('M ...')).toEqual([]);
|
||||
});
|
||||
it('should handle arcs', () => {
|
||||
expect(
|
||||
@ -68,7 +67,7 @@ describe('parse path data', () => {
|
||||
l 50,-25
|
||||
`
|
||||
)
|
||||
).to.deep.equal([
|
||||
).toEqual([
|
||||
{ command: 'M', args: [600, 350] },
|
||||
{ command: 'l', args: [50, -25] },
|
||||
{ command: 'a', args: [25, 25, -30, 0, 1, 50, -25] },
|
||||
@ -93,7 +92,7 @@ describe('stringify path data', () => {
|
||||
{ command: 'H', args: [50] },
|
||||
],
|
||||
})
|
||||
).to.equal('M0 0h10 20 30H40 50');
|
||||
).toEqual('M0 0h10 20 30H40 50');
|
||||
});
|
||||
it('should not combine sequence of moveto', () => {
|
||||
expect(
|
||||
@ -105,7 +104,7 @@ describe('stringify path data', () => {
|
||||
{ command: 'm', args: [40, 50] },
|
||||
],
|
||||
})
|
||||
).to.equal('M0 0M10 10m20 30m40 50');
|
||||
).toEqual('M0 0M10 10m20 30m40 50');
|
||||
});
|
||||
it('should combine moveto and sequence of lineto', () => {
|
||||
expect(
|
||||
@ -119,7 +118,7 @@ describe('stringify path data', () => {
|
||||
{ command: 'L', args: [10, 10] },
|
||||
],
|
||||
})
|
||||
).to.equal('m0 0 10 10M0 0l10 10M0 0 10 10');
|
||||
).toEqual('m0 0 10 10M0 0l10 10M0 0 10 10');
|
||||
expect(
|
||||
stringifyPathData({
|
||||
pathData: [
|
||||
@ -127,7 +126,7 @@ describe('stringify path data', () => {
|
||||
{ command: 'L', args: [10, 10] },
|
||||
],
|
||||
})
|
||||
).to.equal('M0 0 10 10');
|
||||
).toEqual('M0 0 10 10');
|
||||
});
|
||||
it('should avoid space before first, negative and decimals', () => {
|
||||
expect(
|
||||
@ -139,7 +138,7 @@ describe('stringify path data', () => {
|
||||
{ command: 'L', args: [7, 0.8] },
|
||||
],
|
||||
})
|
||||
).to.equal('M0-1.2.3 4 5-.6 7 .8');
|
||||
).toEqual('M0-1.2.3 4 5-.6 7 .8');
|
||||
});
|
||||
it('should configure precision', () => {
|
||||
const pathData = [
|
||||
@ -153,13 +152,13 @@ describe('stringify path data', () => {
|
||||
pathData,
|
||||
precision: 3,
|
||||
})
|
||||
).to.equal('M0-1.988.3 3.142-.3-3.142 100 200');
|
||||
).toEqual('M0-1.988.3 3.142-.3-3.142 100 200');
|
||||
expect(
|
||||
stringifyPathData({
|
||||
pathData,
|
||||
precision: 0,
|
||||
})
|
||||
).to.equal('M0-2 0 3 0-3 100 200');
|
||||
).toEqual('M0-2 0 3 0-3 100 200');
|
||||
});
|
||||
it('allows to avoid spaces after arc flags', () => {
|
||||
const pathData = [
|
||||
@ -172,12 +171,12 @@ describe('stringify path data', () => {
|
||||
pathData,
|
||||
disableSpaceAfterFlags: false,
|
||||
})
|
||||
).to.equal('M0 0A50 50 10 1 0 .2 20a50 50 10 1 0 .2 20');
|
||||
).toEqual('M0 0A50 50 10 1 0 .2 20a50 50 10 1 0 .2 20');
|
||||
expect(
|
||||
stringifyPathData({
|
||||
pathData,
|
||||
disableSpaceAfterFlags: true,
|
||||
})
|
||||
).to.equal('M0 0A50 50 10 10.2 20a50 50 10 10.2 20');
|
||||
).toEqual('M0 0A50 50 10 10.2 20a50 50 10 10.2 20');
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const { collectStylesheet, computeStyle } = require('./style.js');
|
||||
const { querySelector } = require('./xast.js');
|
||||
const svg2js = require('./svgo/svg2js.js');
|
||||
@ -32,35 +31,33 @@ describe('computeStyle', () => {
|
||||
</svg>
|
||||
`);
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#class'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#class'))).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'red' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#two-classes'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'green' },
|
||||
stroke: { type: 'static', inherited: false, value: 'black' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#attribute'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#attribute'))).toEqual(
|
||||
{
|
||||
fill: { type: 'static', inherited: false, value: 'purple' },
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#inline-style'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'grey' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#inheritance'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: true, value: 'yellow' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#nested-inheritance'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: true, value: 'blue' },
|
||||
});
|
||||
});
|
||||
@ -84,7 +81,7 @@ describe('computeStyle', () => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#complex-selector'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'red' },
|
||||
});
|
||||
expect(
|
||||
@ -92,7 +89,7 @@ describe('computeStyle', () => {
|
||||
stylesheet,
|
||||
querySelector(root, '#attribute-over-inheritance')
|
||||
)
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'orange' },
|
||||
});
|
||||
expect(
|
||||
@ -100,7 +97,7 @@ describe('computeStyle', () => {
|
||||
stylesheet,
|
||||
querySelector(root, '#style-rule-over-attribute')
|
||||
)
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'blue' },
|
||||
});
|
||||
expect(
|
||||
@ -108,7 +105,7 @@ describe('computeStyle', () => {
|
||||
stylesheet,
|
||||
querySelector(root, '#inline-style-over-style-rule')
|
||||
)
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'purple' },
|
||||
});
|
||||
});
|
||||
@ -128,7 +125,7 @@ describe('computeStyle', () => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#complex-selector'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'green' },
|
||||
});
|
||||
expect(
|
||||
@ -136,7 +133,7 @@ describe('computeStyle', () => {
|
||||
stylesheet,
|
||||
querySelector(root, '#style-rule-over-inline-style')
|
||||
)
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'green' },
|
||||
});
|
||||
expect(
|
||||
@ -144,7 +141,7 @@ describe('computeStyle', () => {
|
||||
stylesheet,
|
||||
querySelector(root, '#inline-style-over-style-rule')
|
||||
)
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'purple' },
|
||||
});
|
||||
});
|
||||
@ -172,27 +169,23 @@ describe('computeStyle', () => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#media-query'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'dynamic', inherited: false },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#hover'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#hover'))).toEqual({
|
||||
fill: { type: 'dynamic', inherited: false },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#inherited'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#inherited'))).toEqual(
|
||||
{
|
||||
fill: { type: 'dynamic', inherited: true },
|
||||
});
|
||||
}
|
||||
);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#inherited-overriden'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'blue' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#static'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#static'))).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'black' },
|
||||
});
|
||||
});
|
||||
@ -217,17 +210,15 @@ describe('computeStyle', () => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#media-query'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'dynamic', inherited: false },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#kinda-static'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'dynamic', inherited: false },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#static'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#static'))).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'blue' },
|
||||
});
|
||||
});
|
||||
@ -252,17 +243,17 @@ describe('computeStyle', () => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#valid-type'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'red' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#empty-type'))
|
||||
).to.deep.equal({
|
||||
).toEqual({
|
||||
fill: { type: 'static', inherited: false, value: 'green' },
|
||||
});
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#invalid-type'))
|
||||
).to.deep.equal({});
|
||||
).toEqual({});
|
||||
});
|
||||
|
||||
it('ignores keyframes atrule', () => {
|
||||
@ -288,9 +279,7 @@ describe('computeStyle', () => {
|
||||
</svg>
|
||||
`);
|
||||
const stylesheet = collectStylesheet(root);
|
||||
expect(
|
||||
computeStyle(stylesheet, querySelector(root, '#element'))
|
||||
).to.deep.equal({
|
||||
expect(computeStyle(stylesheet, querySelector(root, '#element'))).toEqual({
|
||||
animation: {
|
||||
type: 'static',
|
||||
inherited: false,
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const { visit, detachNodeFromParent } = require('./xast.js');
|
||||
|
||||
const getAst = () => {
|
||||
@ -57,7 +56,7 @@ describe('xast', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(entered).to.deep.equal([
|
||||
expect(entered).toEqual([
|
||||
'root',
|
||||
'element:g',
|
||||
'element:rect',
|
||||
@ -81,7 +80,7 @@ describe('xast', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(exited).to.deep.equal([
|
||||
expect(exited).toEqual([
|
||||
'element:rect',
|
||||
'element:circle',
|
||||
'element:g',
|
||||
@ -103,6 +102,6 @@ describe('xast', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(entered).to.deep.equal(['g', 'ellipse']);
|
||||
expect(entered).toEqual(['g', 'ellipse']);
|
||||
});
|
||||
});
|
||||
|
3130
package-lock.json
generated
3130
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@ -50,8 +50,8 @@
|
||||
"!**/**.test.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "c8 --reporter=html --reporter=text mocha \"test/*/_index.js\" \"**/*.test.js\" --ignore=\"node_modules/**\"",
|
||||
"lint": "eslint --ignore-path .gitignore . && prettier --list-different \"**/*.js\" --ignore-path .gitignore",
|
||||
"test": "jest --coverage",
|
||||
"lint": "eslint --ignore-path .gitignore . && prettier --check \"**/*.js\" --ignore-path .gitignore",
|
||||
"fix": "eslint --ignore-path .gitignore --fix . && prettier --write \"**/*.js\" --ignore-path .gitignore",
|
||||
"typecheck": "tsc",
|
||||
"test-browser": "rollup -c && node ./test/browser.js",
|
||||
@ -83,11 +83,10 @@
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"test/**/*.js",
|
||||
"**/*.test.js"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -105,12 +104,10 @@
|
||||
"@rollup/plugin-commonjs": "^17.1.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^11.2.0",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"c8": "^7.6.0",
|
||||
"chai": "^4.3.4",
|
||||
"@types/jest": "^27.0.0",
|
||||
"del": "^6.0.0",
|
||||
"eslint": "^7.22.0",
|
||||
"mocha": "^8.3.2",
|
||||
"jest": "^27.0.6",
|
||||
"mock-stdin": "^1.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"pixelmatch": "^5.2.1",
|
||||
|
@ -3,7 +3,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const del = require('del');
|
||||
const { expect } = require('chai');
|
||||
const { Command } = require('commander');
|
||||
const svgo = require('../../lib/svgo/coa.js');
|
||||
|
||||
@ -37,7 +36,7 @@ describe('coa', function () {
|
||||
await fs.promises.mkdir(tempFolder);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
afterAll(async () => {
|
||||
await del(tempFolder);
|
||||
});
|
||||
|
||||
@ -105,8 +104,8 @@ describe('coa', function () {
|
||||
'--quiet',
|
||||
]);
|
||||
const optimizedWeight = calcFolderSvgWeight(svgFolderPath);
|
||||
expect(optimizedWeight).gt(0);
|
||||
expect(initWeight).lte(optimizedWeight);
|
||||
expect(optimizedWeight).toBeGreaterThan(0);
|
||||
expect(initWeight).toBeLessThanOrEqual(optimizedWeight);
|
||||
});
|
||||
|
||||
it('should optimize folder recursively', async () => {
|
||||
@ -120,8 +119,8 @@ describe('coa', function () {
|
||||
'--recursive',
|
||||
]);
|
||||
const optimizedWeight = calcFolderSvgWeight(svgFolderPathRecursively);
|
||||
expect(optimizedWeight).gt(0);
|
||||
expect(initWeight).lte(optimizedWeight);
|
||||
expect(optimizedWeight).toBeGreaterThan(0);
|
||||
expect(initWeight).toBeLessThanOrEqual(optimizedWeight);
|
||||
});
|
||||
|
||||
it('should optimize file', async () => {
|
||||
@ -130,7 +129,7 @@ describe('coa', function () {
|
||||
).length;
|
||||
await runProgram(['--input', svgPath, '--output', 'temp.svg', '--quiet']);
|
||||
const optimizedFileLength = fs.readFileSync('temp.svg').length;
|
||||
expect(optimizedFileLength).lte(initialFileLength);
|
||||
expect(optimizedFileLength).toBeLessThanOrEqual(initialFileLength);
|
||||
await del('temp.svg');
|
||||
});
|
||||
|
||||
@ -144,8 +143,8 @@ describe('coa', function () {
|
||||
'--quiet',
|
||||
]);
|
||||
const optimizedWeight = calcFolderSvgWeight(tempFolder);
|
||||
expect(optimizedWeight).gt(0);
|
||||
expect(optimizedWeight).lte(initWeight);
|
||||
expect(optimizedWeight).toBeGreaterThan(0);
|
||||
expect(optimizedWeight).toBeLessThanOrEqual(initWeight);
|
||||
await del('temp.svg');
|
||||
});
|
||||
|
||||
@ -167,7 +166,7 @@ describe('coa', function () {
|
||||
]);
|
||||
} finally {
|
||||
const optimizedFileLength = fs.readFileSync('temp.svg').length;
|
||||
expect(optimizedFileLength).lte(initialFile.length);
|
||||
expect(optimizedFileLength).toBeLessThanOrEqual(initialFile.length);
|
||||
await del('temp.svg');
|
||||
}
|
||||
});
|
||||
@ -182,7 +181,7 @@ describe('coa', function () {
|
||||
'--quiet',
|
||||
]);
|
||||
let optimizedWeight = calcFolderSvgWeight(svgFolderPath);
|
||||
expect(optimizedWeight).lte(initWeight);
|
||||
expect(optimizedWeight).toBeLessThanOrEqual(initWeight);
|
||||
});
|
||||
|
||||
it('should throw error when stated in input folder does not exist', async () => {
|
||||
@ -196,7 +195,7 @@ describe('coa', function () {
|
||||
]);
|
||||
} catch (error) {
|
||||
restoreConsoleError();
|
||||
expect(error.message).to.match(/no such file or directory/);
|
||||
expect(error.message).toMatch(/no such file or directory/);
|
||||
}
|
||||
});
|
||||
|
||||
@ -214,7 +213,7 @@ describe('coa', function () {
|
||||
]);
|
||||
} finally {
|
||||
restoreConsoleLog();
|
||||
expect(output).to.match(/www\.w3\.org\/2000\/svg/);
|
||||
expect(output).toMatch(/www\.w3\.org\/2000\/svg/);
|
||||
}
|
||||
});
|
||||
|
||||
@ -226,7 +225,7 @@ describe('coa', function () {
|
||||
try {
|
||||
await runProgram(['--folder', emptyFolderPath, '--quiet']);
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/No SVG files/);
|
||||
expect(error.message).toMatch(/No SVG files/);
|
||||
}
|
||||
});
|
||||
|
||||
@ -238,7 +237,7 @@ describe('coa', function () {
|
||||
'--quiet',
|
||||
]);
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/No SVG files have been found/);
|
||||
expect(error.message).toMatch(/No SVG files have been found/);
|
||||
}
|
||||
});
|
||||
|
||||
@ -248,7 +247,7 @@ describe('coa', function () {
|
||||
await runProgram(['--show-plugins']);
|
||||
} finally {
|
||||
restoreConsoleLog();
|
||||
expect(output).to.match(/Currently available plugins:/);
|
||||
expect(output).toMatch(/Currently available plugins:/);
|
||||
}
|
||||
});
|
||||
});
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const { expect } = require('chai');
|
||||
const { loadConfig } = require('../../lib/svgo-node.js');
|
||||
const {
|
||||
resolvePluginConfig,
|
||||
@ -20,42 +19,42 @@ describe('config', function () {
|
||||
const removeRasterImages = getPlugin('removeRasterImages', plugins);
|
||||
|
||||
it('removeDoctype plugin should be disabled', function () {
|
||||
expect(removeDoctype.active).to.be.false;
|
||||
expect(removeDoctype.active).toEqual(false);
|
||||
});
|
||||
|
||||
describe('enable plugin with params object', function () {
|
||||
it('removeRasterImages plugin should be enabled', function () {
|
||||
expect(removeRasterImages.active).to.be.true;
|
||||
expect(removeRasterImages.active).toEqual(true);
|
||||
});
|
||||
|
||||
it('removeRasterImages plugin should have property "params"', function () {
|
||||
expect(removeRasterImages).to.have.property('params');
|
||||
expect(removeRasterImages).toHaveProperty('params');
|
||||
});
|
||||
|
||||
it('"params" should be an instance of Object', function () {
|
||||
expect(removeRasterImages.params).to.be.an.instanceOf(Object);
|
||||
expect(removeRasterImages.params).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('"params" should have property "param" with value of true', function () {
|
||||
expect(removeRasterImages.params).to.have.property('param', true);
|
||||
expect(removeRasterImages.params).toHaveProperty('param', true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('extend plugin params with object', function () {
|
||||
it('convertColors plugin should have property "params"', function () {
|
||||
expect(convertColors).to.have.property('params');
|
||||
expect(convertColors).toHaveProperty('params');
|
||||
});
|
||||
|
||||
it('"params" should be an instance of Object', function () {
|
||||
expect(convertColors.params).to.be.an.instanceOf(Object);
|
||||
expect(convertColors.params).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('"params" should have property "shorthex" with value of false', function () {
|
||||
expect(convertColors.params).to.have.property('shorthex', false);
|
||||
expect(convertColors.params).toHaveProperty('shorthex', false);
|
||||
});
|
||||
|
||||
it('"params" should have property "rgb2hex" with value of true', function () {
|
||||
expect(convertColors.params).to.have.property('rgb2hex', true);
|
||||
expect(convertColors.params).toHaveProperty('rgb2hex', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -78,22 +77,22 @@ describe('config', function () {
|
||||
const customPlugin = getPlugin('customPlugin', plugins);
|
||||
|
||||
it('should have "multipass"', function () {
|
||||
expect(config.multipass).to.be.true;
|
||||
expect(config.multipass).toEqual(true);
|
||||
});
|
||||
|
||||
it('config.plugins should have length 3', function () {
|
||||
expect(plugins).to.have.length(3);
|
||||
expect(plugins).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('specified plugins should be enabled', function () {
|
||||
expect(cleanupNumericValues.active).to.equal(true);
|
||||
expect(convertPathData.active).to.equal(true);
|
||||
expect(cleanupNumericValues.active).toEqual(true);
|
||||
expect(convertPathData.active).toEqual(true);
|
||||
});
|
||||
|
||||
it('plugins should inherit floatPrecision top level config', function () {
|
||||
expect(cleanupNumericValues.params.floatPrecision).to.be.equal(2);
|
||||
expect(convertPathData.params.floatPrecision).to.be.equal(2);
|
||||
expect(customPlugin.params.floatPrecision).to.be.equal(2);
|
||||
expect(cleanupNumericValues.params.floatPrecision).toEqual(2);
|
||||
expect(convertPathData.params.floatPrecision).toEqual(2);
|
||||
expect(customPlugin.params.floatPrecision).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
@ -109,11 +108,11 @@ describe('config', function () {
|
||||
const customPlugin = getPlugin('aCustomPlugin', plugins);
|
||||
|
||||
it('custom plugin should be enabled', function () {
|
||||
expect(customPlugin.active).to.be.true;
|
||||
expect(customPlugin.active).toEqual(true);
|
||||
});
|
||||
|
||||
it('custom plugin should have been given a name', function () {
|
||||
expect(customPlugin.name).to.equal('aCustomPlugin');
|
||||
expect(customPlugin.name).toEqual('aCustomPlugin');
|
||||
});
|
||||
});
|
||||
|
||||
@ -128,15 +127,15 @@ describe('config', function () {
|
||||
const customPlugin = getPlugin('aCustomPlugin', plugins);
|
||||
|
||||
it('config.plugins should have length 1', function () {
|
||||
expect(plugins).to.have.length(1);
|
||||
expect(plugins).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('custom plugin should be enabled', function () {
|
||||
expect(customPlugin.active).to.be.true;
|
||||
expect(customPlugin.active).toEqual(true);
|
||||
});
|
||||
|
||||
it('custom plugin should have been given a name', function () {
|
||||
expect(customPlugin.name).to.equal('aCustomPlugin');
|
||||
expect(customPlugin.name).toEqual('aCustomPlugin');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -163,8 +162,8 @@ describe('config', function () {
|
||||
(item) => item.name === 'cleanupIDs'
|
||||
);
|
||||
it('should preserve internal plugins order', () => {
|
||||
expect(removeAttrsIndex).to.equal(41);
|
||||
expect(cleanupIDsIndex).to.equal(11);
|
||||
expect(removeAttrsIndex).toEqual(41);
|
||||
expect(cleanupIDsIndex).toEqual(11);
|
||||
});
|
||||
it('should activate inactive by default plugins', () => {
|
||||
const removeAttrsPlugin = resolvePluginConfig(
|
||||
@ -175,18 +174,18 @@ describe('config', function () {
|
||||
extendedPlugins[cleanupIDsIndex],
|
||||
{}
|
||||
);
|
||||
expect(removeAttrsPlugin.active).to.equal(true);
|
||||
expect(cleanupIDsPlugin.active).to.equal(true);
|
||||
expect(removeAttrsPlugin.active).toEqual(true);
|
||||
expect(cleanupIDsPlugin.active).toEqual(true);
|
||||
});
|
||||
it('should leave not extended inactive plugins to be inactive', () => {
|
||||
const inactivePlugin = resolvePluginConfig(
|
||||
extendedPlugins.find((item) => item.name === 'addClassesToSVGElement'),
|
||||
{}
|
||||
);
|
||||
expect(inactivePlugin.active).to.equal(false);
|
||||
expect(inactivePlugin.active).toEqual(false);
|
||||
});
|
||||
it('should put custom plugins in the end', () => {
|
||||
expect(extendedPlugins[extendedPlugins.length - 1].name).to.equal(
|
||||
expect(extendedPlugins[extendedPlugins.length - 1].name).toEqual(
|
||||
'customPlugin'
|
||||
);
|
||||
});
|
||||
@ -199,8 +198,8 @@ describe('config', function () {
|
||||
extendedPlugins.find((item) => item.name === 'convertTransform'),
|
||||
{}
|
||||
);
|
||||
expect(convertPathDataPlugin.params.floatPrecision).to.equal(1);
|
||||
expect(convertTransformPlugin.params.floatPrecision).to.equal(3);
|
||||
expect(convertPathDataPlugin.params.floatPrecision).toEqual(1);
|
||||
expect(convertTransformPlugin.params.floatPrecision).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
@ -209,35 +208,35 @@ describe('config', function () {
|
||||
const config = await loadConfig(
|
||||
path.join(process.cwd(), './test/config/fixtures/one/two/config.js')
|
||||
);
|
||||
expect(config).to.deep.equal({ plugins: [] });
|
||||
expect(config).toEqual({ plugins: [] });
|
||||
});
|
||||
it('is loaded by relative path to cwd', async () => {
|
||||
const config = await loadConfig(
|
||||
'one/two/config.js',
|
||||
path.join(process.cwd(), './test/config/fixtures')
|
||||
);
|
||||
expect(config).to.deep.equal({ plugins: [] });
|
||||
expect(config).toEqual({ plugins: [] });
|
||||
});
|
||||
it('is searched in cwd and up', async () => {
|
||||
const config = await loadConfig(
|
||||
null,
|
||||
path.join(process.cwd(), './test/config/fixtures/one/two')
|
||||
);
|
||||
expect(config).to.deep.equal({ plugins: [] });
|
||||
expect(config).toEqual({ plugins: [] });
|
||||
});
|
||||
it('gives null when config is not found', async () => {
|
||||
const config = await loadConfig(
|
||||
null,
|
||||
path.join(process.cwd(), './test/config')
|
||||
);
|
||||
expect(config).to.equal(null);
|
||||
expect(config).toEqual(null);
|
||||
});
|
||||
it('is failed when specified config does not exist', async () => {
|
||||
try {
|
||||
await loadConfig('{}');
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/Cannot find module/);
|
||||
expect(error.message).toMatch(/Cannot find module/);
|
||||
}
|
||||
});
|
||||
it('is failed to load when module exports not an object', async () => {
|
||||
@ -247,7 +246,7 @@ describe('config', function () {
|
||||
);
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/Invalid config file/);
|
||||
expect(error.message).toMatch(/Invalid config file/);
|
||||
}
|
||||
try {
|
||||
await loadConfig(
|
||||
@ -255,7 +254,7 @@ describe('config', function () {
|
||||
);
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/Invalid config file/);
|
||||
expect(error.message).toMatch(/Invalid config file/);
|
||||
}
|
||||
try {
|
||||
await loadConfig(
|
||||
@ -263,7 +262,7 @@ describe('config', function () {
|
||||
);
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/Invalid config file/);
|
||||
expect(error.message).toMatch(/Invalid config file/);
|
||||
}
|
||||
});
|
||||
it('handles config errors properly', async () => {
|
||||
@ -274,7 +273,7 @@ describe('config', function () {
|
||||
);
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/plugins is not defined/);
|
||||
expect(error.message).toMatch(/plugins is not defined/);
|
||||
}
|
||||
});
|
||||
it('handles MODULE_NOT_FOUND properly', async () => {
|
||||
@ -284,7 +283,7 @@ describe('config', function () {
|
||||
);
|
||||
expect.fail('Config is loaded successfully');
|
||||
} catch (error) {
|
||||
expect(error.message).to.match(/Cannot find module 'unknown-module'/);
|
||||
expect(error.message).toMatch(/Cannot find module 'unknown-module'/);
|
||||
}
|
||||
});
|
||||
});
|
@ -1,25 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const { createContentItem } = require('../../lib/svgo.js');
|
||||
const JSAPI = require('../../lib/svgo/jsAPI.js');
|
||||
|
||||
describe('svgo api', function () {
|
||||
it('should has createContentItem method', function () {
|
||||
expect(createContentItem).to.be.instanceOf(Function);
|
||||
expect(createContentItem).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
it('should be able to create content item', function () {
|
||||
var item = createContentItem({
|
||||
elem: 'elementName',
|
||||
});
|
||||
expect(item).to.be.instanceOf(JSAPI);
|
||||
expect(item).to.have.ownProperty('elem').equal('elementName');
|
||||
expect(item).toBeInstanceOf(JSAPI);
|
||||
expect(item.elem).toEqual('elementName');
|
||||
});
|
||||
|
||||
it('should be able create content item without argument', function () {
|
||||
var item = createContentItem();
|
||||
expect(item).to.be.instanceOf(JSAPI);
|
||||
expect(item).to.be.empty;
|
||||
expect(item).toBeInstanceOf(JSAPI);
|
||||
expect(item).toEqual({});
|
||||
});
|
||||
});
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const FS = require('fs');
|
||||
const PATH = require('path');
|
||||
const EOL = require('os').EOL;
|
||||
@ -36,11 +35,9 @@ describe('plugins tests', function () {
|
||||
plugins: [plugin],
|
||||
js2svg: { pretty: true },
|
||||
});
|
||||
if (result.error != null) {
|
||||
expect.fail(result.error);
|
||||
}
|
||||
expect(result.error).not.toEqual(expect.anything());
|
||||
//FIXME: results.data has a '\n' at the end while it should not
|
||||
expect(normalize(result.data)).to.equal(should);
|
||||
expect(normalize(result.data)).toEqual(should);
|
||||
});
|
||||
});
|
||||
}
|
@ -1,20 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
var FS = require('fs'),
|
||||
PATH = require('path'),
|
||||
JSAPI = require('../../lib/svgo/jsAPI'),
|
||||
CSSClassList = require('../../lib/svgo/css-class-list'),
|
||||
CSSStyleDeclaration = require('../../lib/svgo/css-style-declaration'),
|
||||
SVG2JS = require('../../lib/svgo/svg2js');
|
||||
const FS = require('fs');
|
||||
const PATH = require('path');
|
||||
const JSAPI = require('../../lib/svgo/jsAPI');
|
||||
const CSSClassList = require('../../lib/svgo/css-class-list');
|
||||
const CSSStyleDeclaration = require('../../lib/svgo/css-style-declaration');
|
||||
const SVG2JS = require('../../lib/svgo/svg2js');
|
||||
|
||||
describe('svg2js', function () {
|
||||
describe('working svg', function () {
|
||||
var filepath = PATH.resolve(__dirname, './test.svg'),
|
||||
root;
|
||||
|
||||
before(function (done) {
|
||||
beforeAll(function (done) {
|
||||
FS.readFile(filepath, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@ -27,30 +25,30 @@ describe('svg2js', function () {
|
||||
|
||||
describe('root', function () {
|
||||
it('should exist', function () {
|
||||
expect(root).to.exist;
|
||||
expect(root).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('should be an instance of Object', function () {
|
||||
expect(root).to.be.an.instanceOf(Object);
|
||||
expect(root).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('should have property "children"', function () {
|
||||
expect(root).to.have.property('children');
|
||||
expect(root).toHaveProperty('children');
|
||||
});
|
||||
});
|
||||
|
||||
describe('root.children', function () {
|
||||
it('should be an instance of Array', function () {
|
||||
expect(root.children).to.be.an.instanceOf(Array);
|
||||
expect(root.children).toBeInstanceOf(Array);
|
||||
});
|
||||
|
||||
it('should have length 4', function () {
|
||||
expect(root.children).to.have.lengthOf(4);
|
||||
expect(root.children).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('the first node should be instruction', () => {
|
||||
expect(root.children[0]).to.include({
|
||||
expect(root.children[0]).toEqual({
|
||||
type: 'instruction',
|
||||
name: 'xml',
|
||||
value: 'version="1.0" encoding="utf-8"',
|
||||
@ -58,7 +56,7 @@ describe('svg2js', function () {
|
||||
});
|
||||
|
||||
it('the second node should be comment', () => {
|
||||
expect(root.children[1]).to.include({
|
||||
expect(root.children[1]).toEqual({
|
||||
type: 'comment',
|
||||
value:
|
||||
'Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)',
|
||||
@ -66,7 +64,7 @@ describe('svg2js', function () {
|
||||
});
|
||||
|
||||
it('the third node should be doctype', () => {
|
||||
expect(root.children[2]).to.deep.include({
|
||||
expect(root.children[2]).toEqual({
|
||||
type: 'doctype',
|
||||
name: 'svg',
|
||||
data: {
|
||||
@ -78,87 +76,86 @@ describe('svg2js', function () {
|
||||
|
||||
describe('name', function () {
|
||||
it('should have property name: "svg"', function () {
|
||||
expect(root.children[3]).to.include({
|
||||
expect(root.children[3]).toEqual(
|
||||
expect.objectContaining({
|
||||
name: 'svg',
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('attributes', function () {
|
||||
describe('root.children[3].attrs', function () {
|
||||
it('should exist', function () {
|
||||
expect(root.children[3].attrs).to.exist;
|
||||
expect(root.children[3].attrs).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('should be an instance of Object', function () {
|
||||
expect(root.children[3].attrs).to.be.an.instanceOf(Object);
|
||||
expect(root.children[3].attrs).toBeInstanceOf(Object);
|
||||
});
|
||||
});
|
||||
|
||||
describe('root.children[3].attrs.version', function () {
|
||||
it('should exist', function () {
|
||||
expect(root.children[3].attrs.version).to.exist;
|
||||
expect(root.children[3].attrs.version).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('should be an instance of Object', function () {
|
||||
expect(root.children[3].attrs.version).to.be.an.instanceOf(Object);
|
||||
expect(root.children[3].attrs.version).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('should have property name: "version"', function () {
|
||||
expect(root.children[3].attrs.version).to.have.property(
|
||||
expect(root.children[3].attrs.version).toHaveProperty(
|
||||
'name',
|
||||
'version'
|
||||
);
|
||||
});
|
||||
|
||||
it('should have property value: "1.1"', function () {
|
||||
expect(root.children[3].attrs.version).to.have.property(
|
||||
'value',
|
||||
'1.1'
|
||||
);
|
||||
expect(root.children[3].attrs.version).toHaveProperty('value', '1.1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('children', function () {
|
||||
it('should exist', function () {
|
||||
expect(root.children[3].children).to.exist;
|
||||
expect(root.children[3].children).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('should be an instance of Array', function () {
|
||||
expect(root.children[3].children).to.be.an.instanceOf(Array);
|
||||
expect(root.children[3].children).toBeInstanceOf(Array);
|
||||
});
|
||||
|
||||
it('should eventually have length 3', function () {
|
||||
expect(root.children[3].children).to.have.lengthOf(3);
|
||||
expect(root.children[3].children).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('text nodes', function () {
|
||||
it('should contain preserved whitespace', function () {
|
||||
const textNode = root.children[3].children[1].children[0].children[1];
|
||||
return expect(textNode.children[0].value).to.equal(' test ');
|
||||
expect(textNode.children[0].value).toEqual(' test ');
|
||||
});
|
||||
});
|
||||
|
||||
describe('API', function () {
|
||||
describe('clone()', function () {
|
||||
it('svg should have property "clone"', function () {
|
||||
expect(root.children[3]).to.have.property('clone');
|
||||
expect(root.children[3]).toHaveProperty('clone');
|
||||
});
|
||||
|
||||
it('svg.clone() should be an instance of JSAPI', function () {
|
||||
expect(root.children[3].clone()).to.be.instanceOf(JSAPI);
|
||||
expect(root.children[3].clone()).toBeInstanceOf(JSAPI);
|
||||
});
|
||||
|
||||
it('root.children[3].children[0].clone() has a valid style property', function () {
|
||||
expect(root.children[3].children[0].clone().style).to.be.instanceof(
|
||||
expect(root.children[3].children[0].clone().style).toBeInstanceOf(
|
||||
CSSStyleDeclaration
|
||||
);
|
||||
});
|
||||
|
||||
it('root.children[3].children[2].clone() has a valid class property', function () {
|
||||
expect(root.children[3].children[2].clone().class).to.be.instanceof(
|
||||
expect(root.children[3].children[2].clone().class).toBeInstanceOf(
|
||||
CSSClassList
|
||||
);
|
||||
});
|
||||
@ -166,129 +163,135 @@ describe('svg2js', function () {
|
||||
|
||||
describe('isElem()', function () {
|
||||
it('svg should have property "isElem"', function () {
|
||||
expect(root.children[3]).to.have.property('isElem');
|
||||
expect(root.children[3]).toHaveProperty('isElem');
|
||||
});
|
||||
|
||||
it('svg.isElem() should be true', function () {
|
||||
expect(root.children[3].isElem()).to.be.true;
|
||||
expect(root.children[3].isElem()).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.isElem("svg") should be true', function () {
|
||||
expect(root.children[3].isElem('svg')).to.be.true;
|
||||
expect(root.children[3].isElem('svg')).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.isElem("trololo") should be false', function () {
|
||||
expect(root.children[3].isElem('trololo')).to.be.false;
|
||||
expect(root.children[3].isElem('trololo')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.isElem(["svg", "trololo"]) should be true', function () {
|
||||
expect(root.children[3].isElem(['svg', 'trololo'])).to.be.true;
|
||||
expect(root.children[3].isElem(['svg', 'trololo'])).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isEmpty()', function () {
|
||||
it('svg should have property "isEmpty"', function () {
|
||||
expect(root.children[3]).to.have.property('isEmpty');
|
||||
expect(root.children[3]).toHaveProperty('isEmpty');
|
||||
});
|
||||
|
||||
it('svg.isEmpty() should be false', function () {
|
||||
expect(root.children[3].isEmpty()).to.be.false;
|
||||
expect(root.children[3].isEmpty()).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.children[0].children[0].isEmpty() should be true', function () {
|
||||
expect(root.children[3].children[0].children[0].isEmpty()).to.be.true;
|
||||
expect(root.children[3].children[0].children[0].isEmpty()).toEqual(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasAttr()', function () {
|
||||
it('svg should have property "hasAttr"', function () {
|
||||
expect(root.children[3]).to.have.property('hasAttr');
|
||||
expect(root.children[3]).toHaveProperty('hasAttr');
|
||||
});
|
||||
|
||||
it('svg.hasAttr() should be true', function () {
|
||||
expect(root.children[3].hasAttr()).to.be.true;
|
||||
expect(root.children[3].hasAttr()).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.hasAttr("xmlns") should be true', function () {
|
||||
expect(root.children[3].hasAttr('xmlns')).to.be.true;
|
||||
expect(root.children[3].hasAttr('xmlns')).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.hasAttr("xmlns", "http://www.w3.org/2000/svg") should be true', function () {
|
||||
expect(
|
||||
root.children[3].hasAttr('xmlns', 'http://www.w3.org/2000/svg')
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.hasAttr("xmlns", "trololo") should be false', function () {
|
||||
expect(root.children[3].hasAttr('xmlns', 'trololo')).to.be.false;
|
||||
expect(root.children[3].hasAttr('xmlns', 'trololo')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.hasAttr("trololo") should be false', function () {
|
||||
expect(root.children[3].hasAttr('trololo')).to.be.false;
|
||||
expect(root.children[3].hasAttr('trololo')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.children[1].hasAttr() should be false', function () {
|
||||
expect(root.children[3].children[1].hasAttr()).to.be.false;
|
||||
expect(root.children[3].children[1].hasAttr()).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('attr()', function () {
|
||||
it('svg should have property "attr"', function () {
|
||||
expect(root.children[3]).to.have.property('attr');
|
||||
expect(root.children[3]).toHaveProperty('attr');
|
||||
});
|
||||
|
||||
it('svg.attr("xmlns") should be an instance of Object', function () {
|
||||
expect(root.children[3].attr('xmlns')).to.be.an.instanceOf(Object);
|
||||
expect(root.children[3].attr('xmlns')).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('svg.attr("xmlns", "http://www.w3.org/2000/svg") should be an instance of Object', function () {
|
||||
expect(
|
||||
root.children[3].attr('xmlns', 'http://www.w3.org/2000/svg')
|
||||
).to.be.an.instanceOf(Object);
|
||||
).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('svg.attr("xmlns", "trololo") should be an undefined', function () {
|
||||
expect(root.children[3].attr('xmlns', 'trololo')).to.not.exist;
|
||||
expect(root.children[3].attr('xmlns', 'trololo')).not.toEqual(
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('svg.attr("trololo") should be an undefined', function () {
|
||||
expect(root.children[3].attr('trololo')).to.not.exist;
|
||||
expect(root.children[3].attr('trololo')).not.toEqual(
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('svg.attr() should be undefined', function () {
|
||||
expect(root.children[3].attr()).to.not.exist;
|
||||
expect(root.children[3].attr()).not.toEqual(expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAttr()', function () {
|
||||
it('svg should have property "removeAttr"', function () {
|
||||
expect(root.children[3]).to.have.property('removeAttr');
|
||||
expect(root.children[3]).toHaveProperty('removeAttr');
|
||||
});
|
||||
|
||||
it('svg.removeAttr("width") should be true', function () {
|
||||
expect(root.children[3].removeAttr('width')).to.be.true;
|
||||
expect(root.children[3].removeAttr('width')).toEqual(true);
|
||||
|
||||
expect(root.children[3].hasAttr('width')).to.be.false;
|
||||
expect(root.children[3].hasAttr('width')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.removeAttr("height", "120px") should be true', function () {
|
||||
expect(root.children[3].removeAttr('height', '120px')).to.be.true;
|
||||
expect(root.children[3].removeAttr('height', '120px')).toEqual(true);
|
||||
|
||||
expect(root.children[3].hasAttr('height')).to.be.false;
|
||||
expect(root.children[3].hasAttr('height')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.removeAttr("x", "1px") should be false', function () {
|
||||
expect(root.children[3].removeAttr('x', '1px')).to.be.false;
|
||||
expect(root.children[3].removeAttr('x', '1px')).toEqual(false);
|
||||
|
||||
expect(root.children[3].hasAttr('x')).to.be.true;
|
||||
expect(root.children[3].hasAttr('x')).toEqual(true);
|
||||
});
|
||||
|
||||
it('svg.removeAttr("z") should be false', function () {
|
||||
expect(root.children[3].removeAttr('z')).to.be.false;
|
||||
expect(root.children[3].removeAttr('z')).toEqual(false);
|
||||
});
|
||||
|
||||
it('svg.removeAttr() should be false', function () {
|
||||
expect(root.children[3].removeAttr()).to.be.false;
|
||||
expect(root.children[3].removeAttr()).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -299,27 +302,27 @@ describe('svg2js', function () {
|
||||
};
|
||||
|
||||
it('svg should have property "addAttr"', function () {
|
||||
expect(root.children[3]).to.have.property('addAttr');
|
||||
expect(root.children[3]).toHaveProperty('addAttr');
|
||||
});
|
||||
|
||||
it('svg.addAttr(attr) should be an instance of Object', function () {
|
||||
expect(root.children[3].addAttr(attr)).to.be.an.instanceOf(Object);
|
||||
expect(root.children[3].addAttr(attr)).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('svg.children[1].children[0].addAttr(attr) should be an instance of Object', function () {
|
||||
expect(
|
||||
root.children[3].children[1].children[0].addAttr(attr)
|
||||
).to.be.an.instanceOf(Object);
|
||||
).toBeInstanceOf(Object);
|
||||
});
|
||||
|
||||
it('svg.addAttr() should be false', function () {
|
||||
expect(root.children[3].addAttr()).to.be.false;
|
||||
expect(root.children[3].addAttr()).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eachAttr()', function () {
|
||||
it('svg should have property "eachAttr"', function () {
|
||||
expect(root.children[3]).to.have.property('eachAttr');
|
||||
expect(root.children[3]).toHaveProperty('eachAttr');
|
||||
});
|
||||
|
||||
it('svg.children[0].eachAttr(function() {}) should be true', function () {
|
||||
@ -327,13 +330,13 @@ describe('svg2js', function () {
|
||||
root.children[3].children[0].eachAttr(function (attr) {
|
||||
attr.value = '1';
|
||||
})
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
|
||||
expect(root.children[3].children[0].attr('type').value).to.equal('1');
|
||||
expect(root.children[3].children[0].attr('type').value).toEqual('1');
|
||||
});
|
||||
|
||||
it('svg.children[1].eachAttr(function() {}) should be false', function () {
|
||||
expect(root.children[3].children[1].eachAttr()).to.be.false;
|
||||
expect(root.children[3].children[1].eachAttr()).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -344,7 +347,7 @@ describe('svg2js', function () {
|
||||
root,
|
||||
error;
|
||||
|
||||
before(function (done) {
|
||||
beforeAll(function (done) {
|
||||
FS.readFile(filepath, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@ -362,13 +365,13 @@ describe('svg2js', function () {
|
||||
|
||||
describe('root', function () {
|
||||
it('should have property "error"', function () {
|
||||
expect(root).to.have.property('error');
|
||||
expect(root).toHaveProperty('error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('root.error', function () {
|
||||
it('should be "Error in parsing SVG: Unexpected close tag"', function () {
|
||||
expect(root.error).to.equal(
|
||||
expect(root.error).toEqual(
|
||||
'Error in parsing SVG: Unexpected close tag\nLine: 10\nColumn: 15\nChar: >'
|
||||
);
|
||||
});
|
||||
@ -376,7 +379,7 @@ describe('svg2js', function () {
|
||||
|
||||
describe('error', function () {
|
||||
it('should not be thrown', function () {
|
||||
expect(error).to.not.exist;
|
||||
expect(error).not.toEqual(expect.anything());
|
||||
});
|
||||
});
|
||||
});
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { EOL } = require('os');
|
||||
@ -25,14 +24,14 @@ describe('svgo', () => {
|
||||
plugins: [],
|
||||
js2svg: { pretty: true, indent: 2 },
|
||||
});
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(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);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
it('should pass multipass count to plugins', async () => {
|
||||
const [original, expected] = await parseFixture('multipass-prefix-ids.svg');
|
||||
@ -44,24 +43,24 @@ describe('svgo', () => {
|
||||
},
|
||||
]),
|
||||
});
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
it('should handle plugins order properly', async () => {
|
||||
const [original, expected] = await parseFixture('plugins-order.svg');
|
||||
const result = optimize(original, { input: 'file', path: 'input.svg' });
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
it('should handle parse error', async () => {
|
||||
const fixture = await fs.promises.readFile(
|
||||
path.resolve(__dirname, 'invalid.svg')
|
||||
);
|
||||
const result = optimize(fixture, { input: 'file', path: 'input.svg' });
|
||||
expect(result.error).to.match(/Error in parsing SVG/);
|
||||
expect(result.path).to.equal('input.svg');
|
||||
expect(result.error).toMatch(/Error in parsing SVG/);
|
||||
expect(result.path).toEqual('input.svg');
|
||||
});
|
||||
it('should handle empty svg tag', async () => {
|
||||
const result = optimize('<svg />', { input: 'file', path: 'input.svg' });
|
||||
expect(result.data).to.equal('<svg/>');
|
||||
expect(result.data).toEqual('<svg/>');
|
||||
});
|
||||
it('should preserve style specifity over attributes', async () => {
|
||||
const [original, expected] = await parseFixture('style-specifity.svg');
|
||||
@ -70,7 +69,7 @@ describe('svgo', () => {
|
||||
path: 'input.svg',
|
||||
js2svg: { pretty: true },
|
||||
});
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
it('should inline entities', async () => {
|
||||
const [original, expected] = await parseFixture('entities.svg');
|
||||
@ -79,7 +78,7 @@ describe('svgo', () => {
|
||||
plugins: [],
|
||||
js2svg: { pretty: true },
|
||||
});
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
it('should preserve whitespaces between tspan tags', async () => {
|
||||
const [original, expected] = await parseFixture('whitespaces.svg');
|
||||
@ -87,6 +86,6 @@ describe('svgo', () => {
|
||||
path: 'input.svg',
|
||||
js2svg: { pretty: true },
|
||||
});
|
||||
expect(normalize(result.data)).to.equal(expected);
|
||||
expect(normalize(result.data)).toEqual(expected);
|
||||
});
|
||||
});
|
@ -64,18 +64,18 @@
|
||||
"plugins/sortDefsChildren.js",
|
||||
"lib/svgo/jsAPI.js",
|
||||
"test/browser.js",
|
||||
"test/coa/_index.js",
|
||||
"test/config/_index.js",
|
||||
"test/coa/_index.test.js",
|
||||
"test/config/_index.test.js",
|
||||
"test/config/fixtures/invalid-array.js",
|
||||
"test/config/fixtures/invalid-null.js",
|
||||
"test/config/fixtures/invalid-string.js",
|
||||
"test/config/fixtures/invalid/svgo.config.js",
|
||||
"test/config/fixtures/module-not-found.js",
|
||||
"test/config/fixtures/one/two/config.js",
|
||||
"test/jsapi/_index.js",
|
||||
"test/plugins/_index.js",
|
||||
"test/jsapi/_index.test.js",
|
||||
"test/plugins/_index.test.js",
|
||||
"test/regression.js",
|
||||
"test/svg2js/_index.js",
|
||||
"test/svgo/_index.js"
|
||||
"test/svg2js/_index.test.js",
|
||||
"test/svgo/_index.test.js"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user