Skip to content

Commit

Permalink
fix(webdriverjs): Reject with actual Errors (not strings)
Browse files Browse the repository at this point in the history
Closes #422
Ref #421
Ref #387
Ref #308 (somewhat)
Ref #207
  • Loading branch information
stephenmathieson committed Jan 10, 2022
1 parent 4d09009 commit 96a594a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
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 \n%s'), e.message, e.stack);
}

console.error(
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/lib/axe-test-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const testPages = async (
.get(currentUrl)
.then(() => {
return driver.executeAsyncScript(`
const callback = arguments[arguments.length - 1];
const script = document.createElement('script');
script.innerHTML = 'document.documentElement.classList.add("deque-axe-is-ready");'
document.documentElement.appendChild(script);
callback();
const callback = arguments[arguments.length - 1];
const script = document.createElement('script');
script.innerHTML = 'document.documentElement.classList.add("deque-axe-is-ready");'
document.documentElement.appendChild(script);
callback();
`);
})
.then(() => {
Expand Down Expand Up @@ -84,7 +84,7 @@ const testPages = async (
events?.startTimer('axe-core execution time');
}

axe.analyze((err: string, results: AxeResults) => {
axe.analyze((err: Error | null, results: AxeResults) => {
if (config.timer) {
events?.endTimer('axe-core execution time');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxeResults } from 'axe-core';
import type { WebDriver, Builder } from 'selenium-webdriver';
import type { Options } from 'selenium-webdriver/chrome';

export interface EventParams {
silentMode: boolean;
timer: boolean;
Expand Down
9 changes: 2 additions & 7 deletions packages/webdriverjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { WebDriver } from 'selenium-webdriver';
import { RunOptions, Spec, AxeResults, ContextObject } from 'axe-core';
import { source } from 'axe-core';
import {
CallbackFunction,
BuilderOptions,
PartialResults,
Selector
} from './types';
import { CallbackFunction, BuilderOptions, Selector } from './types';
import { normalizeContext } from './utils/index';
import AxeInjector from './axe-injector';
import {
Expand Down Expand Up @@ -136,7 +131,7 @@ class AxeBuilder {
.catch((err: Error) => {
// When using a callback, do *not* reject the wrapping Promise. This prevents having to handle the same error twice.
if (callback) {
callback(err.message, null);
callback(err, null);
} else {
reject(err);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webdriverjs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface AxeInjectorParams extends Options {
}

export type CallbackFunction = (
error: string | null,
error: Error | null,
results: AxeResults | null
) => void;

Expand Down

0 comments on commit 96a594a

Please sign in to comment.