@axe-core/watcher
Advanced tools
Comparing version 3.16.0-next.acef2936 to 3.16.0-next.b08463c8
@@ -11,3 +11,3 @@ import type { Debugger } from 'debug'; | ||
constructor({ debugLoggerName }: ControllerParams); | ||
start(): Promise<void>; | ||
start(): void; | ||
stop(): Promise<void>; | ||
@@ -14,0 +14,0 @@ analyze({ __Method, __UserRequestedAnalyze }?: { |
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const updateAutoAnalyze_1 = __importDefault(require("./utils/updateAutoAnalyze")); | ||
const sendResultsToServer_1 = __importDefault(require("./sendResultsToServer")); | ||
@@ -15,40 +14,35 @@ const createDebugger_1 = __importDefault(require("./createDebugger")); | ||
} | ||
async start() { | ||
(0, updateAutoAnalyze_1.default)(true); | ||
start() { | ||
this.debugLogger(`Start: Invoked`); | ||
this.isStopped = false; | ||
await this.executeScript(() => { | ||
if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) { | ||
return Promise.resolve(); | ||
} | ||
return new Promise(resolve => { | ||
const fn = () => { | ||
window.removeEventListener('axe:start-auto-mode-done', fn); | ||
resolve(); | ||
}; | ||
window.addEventListener('axe:start-auto-mode-done', fn); | ||
const event = new CustomEvent('axe:start-auto-mode'); | ||
window.dispatchEvent(event); | ||
}); | ||
}); | ||
} | ||
async stop() { | ||
(0, updateAutoAnalyze_1.default)(false); | ||
this.isStopped = true; | ||
await this.executeScript(() => { | ||
this.debugLogger(`Stop: Invoked (${this.isStopped ? 'not analyzing' : 'may analyze implicitly'})`); | ||
if (this.isStopped) { | ||
return; | ||
} | ||
const result = await this.executeScript(() => { | ||
if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) { | ||
return Promise.resolve(); | ||
return Promise.resolve({ message: 'Skipped - Invalid protocol' }); | ||
} | ||
return new Promise(resolve => { | ||
const fn = () => { | ||
window.removeEventListener('axe:stop-auto-mode-done', fn); | ||
resolve(); | ||
const fn = (event) => { | ||
window.removeEventListener('axe:manual-mode-analyze-done', fn); | ||
resolve(event.detail); | ||
}; | ||
window.addEventListener('axe:stop-auto-mode-done', fn); | ||
const event = new CustomEvent('axe:stop-auto-mode'); | ||
window.addEventListener('axe:manual-mode-analyze-done', fn); | ||
const event = new CustomEvent('axe:manual-mode-analyze', { | ||
detail: { userRequestedAnalyze: false } | ||
}); | ||
window.dispatchEvent(event); | ||
}); | ||
}); | ||
this.debugLogger(`Stop: ${result.message}`); | ||
this.isStopped = true; | ||
} | ||
async analyze({ __Method, __UserRequestedAnalyze = true } = {}) { | ||
this.debugLogger(`Analyze: Invoked${__Method ? ` - ${__Method}` : ''}`); | ||
this.debugLogger(`Analyze: Invoked${__Method ? ` - ${__Method}` : ''}`, { | ||
isStopped: this.isStopped, | ||
__UserRequestedAnalyze | ||
}); | ||
if (this.isStopped && !__UserRequestedAnalyze) { | ||
@@ -61,3 +55,3 @@ this.debugLogger('Analyze: Skipped', { | ||
} | ||
const result = await this.executeScript((userRequestedAnalyze) => { | ||
const result = await this.executeScript(({ userRequestedAnalyze, isStopped }) => { | ||
if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) { | ||
@@ -73,12 +67,15 @@ return Promise.resolve({ message: 'Skipped - Invalid protocol' }); | ||
const event = new CustomEvent('axe:manual-mode-analyze', { | ||
detail: { userRequestedAnalyze } | ||
detail: { userRequestedAnalyze, isStopped } | ||
}); | ||
window.dispatchEvent(event); | ||
}); | ||
}, __UserRequestedAnalyze); | ||
}, { | ||
userRequestedAnalyze: __UserRequestedAnalyze, | ||
isStopped: this.isStopped | ||
}); | ||
this.debugLogger(`Analyze: ${result.message}`); | ||
} | ||
async flush() { | ||
this.debugLogger('Flush: Invoked (may analyze implicitly)'); | ||
const results = await this.executeScript(() => { | ||
this.debugLogger(`Flush: Invoked (${this.isStopped ? 'auto-analysis stopped' : 'may analyze implicitly'})`); | ||
const results = await this.executeScript((isStopped) => { | ||
if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) { | ||
@@ -99,6 +96,8 @@ return Promise.resolve([]); | ||
window.addEventListener('axe:flush-end', onFlushEnd); | ||
const event = new CustomEvent('axe:flush-start'); | ||
const event = new CustomEvent('axe:flush-start', { | ||
detail: { isStopped } | ||
}); | ||
window.dispatchEvent(event); | ||
}); | ||
}); | ||
}, this.isStopped); | ||
this.debugLogger(`Flush: Received ${results.length} results`); | ||
@@ -105,0 +104,0 @@ await (0, sendResultsToServer_1.default)({ |
@@ -6,3 +6,3 @@ /*! Copyright Deque 2021-2023 All Rights Reserved */ | ||
export { playwrightConfig, PlaywrightController, wrapPlaywright, wrapPlaywrightPage } from './playwright'; | ||
export { default as playwrightTest } from './playwrightTest'; | ||
export { default as playwrightTest, type PageWithAxeWatcher as PlaywrightTestPageWithAxeWatcher } from './playwrightTest'; | ||
export { cypressConfig } from './cypress'; |
@@ -14,3 +14,3 @@ import type { LaunchOptions, Page, BrowserContext } from 'playwright-core'; | ||
private driver; | ||
constructor(driver: Page); | ||
constructor(driver: Page, isStopped?: boolean); | ||
protected executeScript<T>(fn: string | (() => Promise<T>), ...args: unknown[]): Promise<T>; | ||
@@ -17,0 +17,0 @@ } |
@@ -29,6 +29,7 @@ "use strict"; | ||
class PlaywrightController extends Controller_1.default { | ||
constructor(driver) { | ||
constructor(driver, isStopped = false) { | ||
super({ debugLoggerName: 'PlaywrightController' }); | ||
(0, assertVariablesWereWritten_1.assertVariablesWereWritten)('Playwright', 'playwrightConfig()'); | ||
this.driver = driver; | ||
this.isStopped = isStopped; | ||
} | ||
@@ -35,0 +36,0 @@ async executeScript(fn, ...args) { |
@@ -1,4 +0,10 @@ | ||
import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, Expect } from '@playwright/test'; | ||
import { type Options } from './playwright'; | ||
type Test = TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>; | ||
import type { TestType, Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, Expect } from '@playwright/test'; | ||
import { PlaywrightController, type Options } from './playwright'; | ||
export type PageWithAxeWatcher = Page & { | ||
axeWatcher: PlaywrightController; | ||
}; | ||
type Test = TestType<PlaywrightTestArgs & PlaywrightTestOptions & Fixtures, PlaywrightWorkerArgs & PlaywrightWorkerOptions>; | ||
type Fixtures = { | ||
page: PageWithAxeWatcher; | ||
}; | ||
interface ReturnValue { | ||
@@ -5,0 +11,0 @@ test: Test; |
@@ -21,2 +21,3 @@ "use strict"; | ||
} | ||
const isStopped = typeof axe.autoAnalyze === 'undefined' ? false : !axe.autoAnalyze; | ||
(0, writeVariables_1.default)(axe); | ||
@@ -35,10 +36,12 @@ const test = base.extend({ | ||
page: async ({ page }, use) => { | ||
controller = new playwright_1.PlaywrightController(page); | ||
page = (0, playwright_1.wrapPlaywrightPage)(page, controller); | ||
controller = page.axeWatcher; | ||
if (!controller) { | ||
controller = new playwright_1.PlaywrightController(page, isStopped); | ||
page.axeWatcher = controller; | ||
page = (0, playwright_1.wrapPlaywrightPage)(page, controller); | ||
} | ||
await use(page); | ||
await controller.flush(); | ||
} | ||
}); | ||
test.afterEach(async () => { | ||
await (controller === null || controller === void 0 ? void 0 : controller.flush()); | ||
}); | ||
const expect = test.expect; | ||
@@ -45,0 +48,0 @@ return { test, expect }; |
{ | ||
"name": "@axe-core/watcher", | ||
"version": "3.16.0-next.acef2936", | ||
"version": "3.16.0-next.b08463c8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "UNLICENSED", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
2167729
96
3235