Skip to content

Commit

Permalink
fix(cli): provide a more robust error message if analysis fails (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zidious committed Jan 11, 2022
1 parent 4d09009 commit 9f1fa5d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions packages/cli/src/bin/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ describe('cli', () => {
'Violation of "marquee" with 1 occurrences!'
);
});

it('should throw error if CSS selector is not found', async () => {
const result = await runCLI(
`file://${SIMPLE_HTML_FILE}`,
'--include',
'#hazaar',
'--show-errors'
);

assert.include(
result.stderr,
'javascript error: No elements found for include in page Context'
);
assert.equal(result.exitCode, 1);
});

it('should throw error if invalid selector is provided', async () => {
const result = await runCLI(
`file://${SIMPLE_HTML_FILE}`,
'--include',
'#123',
'--show-errors'
);

assert.include(result.stderr, 'is not a valid selector');
assert.equal(result.exitCode, 1);
});
});

describe('--exclude', () => {
Expand All @@ -194,6 +221,18 @@ describe('cli', () => {
'Violation of "marquee" with 1 occurrences!'
);
});

it('should throw error if invalid selector is provided', async () => {
const result = await runCLI(
`file://${SIMPLE_HTML_FILE}`,
'--exclude',
'#123',
'--show-errors'
);

assert.include(result.stderr, 'is not a valid selector');
assert.equal(result.exitCode, 1);
});
});

describe('--disable', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const cli = async (
if (!showErrors) {
console.error(error('An error occurred while testing this page.'));
} else {
console.error(error('Error: %j \n $s'), e.message, e.stack);
console.error(error('Error: %s'), e);
}

console.error(
Expand Down

0 comments on commit 9f1fa5d

Please sign in to comment.