From 96a594aa8ef191cf96b98ae7a638e577ba08d24a Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Mon, 10 Jan 2022 17:33:39 -0500 Subject: [PATCH 1/2] fix(webdriverjs): Reject with actual `Error`s (not strings) Closes #422 Ref #421 Ref #387 Ref #308 (somewhat) Ref #207 --- packages/cli/src/bin/index.ts | 2 +- packages/cli/src/lib/axe-test-urls.ts | 12 ++++++------ packages/cli/src/types.ts | 2 +- packages/webdriverjs/src/index.ts | 9 ++------- packages/webdriverjs/src/types.ts | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/bin/index.ts b/packages/cli/src/bin/index.ts index 1d3db6e1..e4640a7a 100644 --- a/packages/cli/src/bin/index.ts +++ b/packages/cli/src/bin/index.ts @@ -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( diff --git a/packages/cli/src/lib/axe-test-urls.ts b/packages/cli/src/lib/axe-test-urls.ts index 6bb7cfa2..1474e620 100644 --- a/packages/cli/src/lib/axe-test-urls.ts +++ b/packages/cli/src/lib/axe-test-urls.ts @@ -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(() => { @@ -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'); } diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index d06e7f3d..dc98ba98 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -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; diff --git a/packages/webdriverjs/src/index.ts b/packages/webdriverjs/src/index.ts index 830990ab..487a5264 100644 --- a/packages/webdriverjs/src/index.ts +++ b/packages/webdriverjs/src/index.ts @@ -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 { @@ -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); } diff --git a/packages/webdriverjs/src/types.ts b/packages/webdriverjs/src/types.ts index 4e7252e8..81334ea2 100644 --- a/packages/webdriverjs/src/types.ts +++ b/packages/webdriverjs/src/types.ts @@ -18,7 +18,7 @@ export interface AxeInjectorParams extends Options { } export type CallbackFunction = ( - error: string | null, + error: Error | null, results: AxeResults | null ) => void; From 340c7fd2d0bc6c3c13d69c99606225517e7f2d60 Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Mon, 10 Jan 2022 17:36:44 -0500 Subject: [PATCH 2/2] remove trailing space (ocd) --- packages/cli/src/bin/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/bin/index.ts b/packages/cli/src/bin/index.ts index e4640a7a..9fc38ed2 100644 --- a/packages/cli/src/bin/index.ts +++ b/packages/cli/src/bin/index.ts @@ -150,7 +150,7 @@ const cli = async ( if (!showErrors) { console.error(error('An error occurred while testing this page.')); } else { - console.error(error('Error: %s \n%s'), e.message, e.stack); + console.error(error('Error: %s\n%s'), e.message, e.stack); } console.error(