Skip to content

Commit

Permalink
fix(webdriverjs): Reject with actual Errors (not strings) (#423)
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 authored Jan 25, 2022
1 parent 0e566c2 commit 3fdb50a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
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 3fdb50a

Please sign in to comment.