mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Add better parser errors (#1553)
Old SVGO errors were not very helpful. Packages like cssnano (postcss-svgo) had to deal with a lot of issues which are hard to debug with old errors. ``` Error: Error in parsing SVG: Unquoted attribute value Line: 1 Column: 29 Char: 6 File: input.svg ``` New errors are more informative and may solve many struggles ``` Error: SvgoParserError: input.svg:2:29: Unquoted attribute value 1 | <svg viewBox="0 0 120 120"> > 2 | <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/> | ^ 3 | </svg> 4 | ```
This commit is contained in:
33
test/cli/cli.test.js
Normal file
33
test/cli/cli.test.js
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const { spawn } = require('child_process');
|
||||
const stripAnsi = require('strip-ansi');
|
||||
|
||||
test('should exit with 1 code on syntax error', async () => {
|
||||
const proc = spawn('node', ['../../bin/svgo', 'invalid.svg'], {
|
||||
cwd: __dirname,
|
||||
});
|
||||
const [code, stderr] = await Promise.all([
|
||||
new Promise((resolve) => {
|
||||
proc.on('close', (code) => {
|
||||
resolve(code);
|
||||
});
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
proc.stderr.on('data', (error) => {
|
||||
resolve(error.toString());
|
||||
});
|
||||
}),
|
||||
]);
|
||||
expect(code).toEqual(1);
|
||||
expect(stripAnsi(stderr))
|
||||
.toEqual(`SvgoParserError: invalid.svg:2:27: Unquoted attribute value
|
||||
|
||||
1 | <svg>
|
||||
> 2 | <rect x="0" y="0" width=10" height="20" />
|
||||
| ^
|
||||
3 | </svg>
|
||||
4 |
|
||||
|
||||
`);
|
||||
});
|
Reference in New Issue
Block a user