Skip to content

Commit

Permalink
Parsing errors are now handled differently - no error is raised in th…
Browse files Browse the repository at this point in the history
…e code
  • Loading branch information
macbre committed Aug 12, 2021
1 parent 303c2f9 commit 6163fd2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
6 changes: 1 addition & 5 deletions lib/css-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,7 @@ class CSSAnalyzer {
this.emit("css", css);

// now go through parsed CSS tree and emit events for rules
try {
this.run();
} catch (ex) {
return ex;
}
this.run();

this.emit("report");

Expand Down
2 changes: 1 addition & 1 deletion rules/specificity.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function rule(analyzer) {
parts;

/* istanbul ignore if */
if (!selectorSpecificity) {
if (!selectorSpecificity || !selectorSpecificity[0]) {
debug("not counted for %s!", selector);
return;
}
Expand Down
10 changes: 2 additions & 8 deletions test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ const tests = [
check: /css parameter passed is not a string/,
code: analyzer.EXIT_CSS_PASSED_IS_NOT_STRING
},
// issue #98
{
name: 'Invalid CSS selector',
css: 'foo, bar, {color: red}',
check: /Unable to parse "" selector. Rule position start @ 1:1, end @ 1:23/,
code: analyzer.EXIT_PARSING_FAILED
}
];

describe('Errors handling', () => {
Expand All @@ -37,12 +30,13 @@ describe('Errors handling', () => {
it('should raise an error with correct error code', async () => {
try {
await analyzer(test.css);
assert.fail("Expected to fail");
assert.fail("analyzer() is expected to fail");
}
catch(err) {
assert.strictEqual(err instanceof Error, true, 'Error should be thrown');

if (!test.check.test(err.toString())) {
console.error('Got instead: ', err);
assert.fail(`${test.name} case raised: ${err.message} (expected ${test.check})`);
}

Expand Down

0 comments on commit 6163fd2

Please sign in to comment.