Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): provide a more robust error message if analysis fails #421

Merged
merged 5 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 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,31 @@ 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'
);

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'
);

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

describe('--exclude', () => {
Expand All @@ -194,6 +219,17 @@ 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'
);

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
1 change: 1 addition & 0 deletions packages/cli/src/lib/axe-test-urls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as WebDriver from 'selenium-webdriver';
import AxeBuilder from '@axe-core/webdriverjs';
import { AxeResults } from 'axe-core';
import { error } from '../lib/utils';
Zidious marked this conversation as resolved.
Show resolved Hide resolved
import { EventResponse, ConfigParams } from '../types';

const testPages = async (
Expand Down