@axe-core/playwright
Advanced tools
Comparing version 4.2.3-alpha.183 to 4.2.3-alpha.184
@@ -9,2 +9,3 @@ import type { RunOptions, AxeResults } from 'axe-core'; | ||
private source; | ||
private legacyMode; | ||
constructor({ page, axeSource }: AxePlaywrightParams); | ||
@@ -52,2 +53,10 @@ /** | ||
/** | ||
* Use frameMessenger with <same_origin_only> | ||
* | ||
* This disables use of axe.runPartial() which is called in each frame, and | ||
* axe.finishRun() which is called in a blank page. This uses axe.run() instead, | ||
* but with the restriction that cross-origin frames will not be tested. | ||
*/ | ||
setLegacyMode(legacyMode?: boolean): this; | ||
/** | ||
* Perform analysis and retrieve results. *Does not chain.* | ||
@@ -54,0 +63,0 @@ * @return Promise<Result | Error> |
@@ -46,2 +46,3 @@ "use strict"; | ||
var page = _a.page, axeSource = _a.axeSource; | ||
this.legacyMode = false; | ||
var axePath = require.resolve('axe-core'); | ||
@@ -133,2 +134,14 @@ var source = fs.readFileSync(axePath, 'utf-8'); | ||
/** | ||
* Use frameMessenger with <same_origin_only> | ||
* | ||
* This disables use of axe.runPartial() which is called in each frame, and | ||
* axe.finishRun() which is called in a blank page. This uses axe.run() instead, | ||
* but with the restriction that cross-origin frames will not be tested. | ||
*/ | ||
AxeBuilder.prototype.setLegacyMode = function (legacyMode) { | ||
if (legacyMode === void 0) { legacyMode = true; } | ||
this.legacyMode = legacyMode; | ||
return this; | ||
}; | ||
/** | ||
* Perform analysis and retrieve results. *Does not chain.* | ||
@@ -149,3 +162,3 @@ * @return Promise<Result | Error> | ||
runPartialDefined = _b.sent(); | ||
if (!!runPartialDefined) return [3 /*break*/, 3]; | ||
if (!(!runPartialDefined || this.legacyMode)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.runLegacy(context)]; | ||
@@ -199,3 +212,3 @@ case 2: | ||
AxeBuilder.prototype.script = function () { | ||
return "\n " + this.source + "\n axe.configure({ \n allowedOrigins: ['<unsafe_all_origins>'], \n branding: { application: 'playwright' }\n })\n "; | ||
return "\n " + this.source + "\n axe.configure({\n " + (this.legacyMode ? '' : 'allowedOrigins: ["<unsafe_all_origins>"],') + "\n branding: { application: 'playwright' }\n })\n "; | ||
}; | ||
@@ -202,0 +215,0 @@ AxeBuilder.prototype.runLegacy = function (context) { |
{ | ||
"name": "@axe-core/playwright", | ||
"version": "4.2.3-alpha.183+321a055", | ||
"version": "4.2.3-alpha.184+f9d021b", | ||
"description": "Provides a method to inject and analyze web pages using axe", | ||
@@ -80,3 +80,3 @@ "contributors": [ | ||
}, | ||
"gitHead": "321a0550d13c5c267af3b09adfa212efc1d8279f" | ||
"gitHead": "f9d021b49487e2a0f804f61e9b6e09a26b69a6e4" | ||
} |
@@ -71,2 +71,17 @@ # @axe-core/playwright | ||
### AxeBuilder#analyze(): Promise<axe.Results | Error> | ||
Performs analysis and passes any encountered error and/or the result object. | ||
```js | ||
new AxeBuilder({ page }) | ||
.analyze() | ||
.then(results => { | ||
console.log(results); | ||
}) | ||
.catch(e => { | ||
// Do something with error | ||
}); | ||
``` | ||
### AxeBuilder#include(selector: String) | ||
@@ -128,15 +143,14 @@ | ||
### AxeBuilder#analyze(): Promise<axe.Results | Error> | ||
### AxeBuilder#setLegacyMode(legacyMode: boolean = true) | ||
Performs analysis and passes any encountered error and/or the result object. | ||
Set the frame testing method to "legacy mode". In this mode, axe will not open a blank page in which to aggregate its results. This can be used in an environment where opening a blank page is causes issues. | ||
With legacy mode turned on, axe will fall back to its test solution prior to the 4.3 release, but with cross-origin frame testing disabled. The `frame-tested` rule will report which frames were untested. | ||
**Important** Use of `.setLegacyMode()` is a last resort. If you find there is no other solution, please [report this as an issue](https://github.com/dequelabs/axe-core-npm/issues/). | ||
```js | ||
new AxeBuilder({ page }) | ||
.analyze() | ||
.then(results => { | ||
console.log(results); | ||
}) | ||
.catch(e => { | ||
// Do something with error | ||
}); | ||
const axe = new AxeBuilder({ page }).setLegacyMode(); | ||
const result = await axe.analyze(); | ||
axe.setLegacyMode(false); // Disables legacy mode | ||
``` |
@@ -25,2 +25,4 @@ import * as fs from 'fs'; | ||
private source: string; | ||
private legacyMode = false; | ||
constructor({ page, axeSource }: AxePlaywrightParams) { | ||
@@ -127,2 +129,14 @@ const axePath = require.resolve('axe-core'); | ||
/** | ||
* Use frameMessenger with <same_origin_only> | ||
* | ||
* This disables use of axe.runPartial() which is called in each frame, and | ||
* axe.finishRun() which is called in a blank page. This uses axe.run() instead, | ||
* but with the restriction that cross-origin frames will not be tested. | ||
*/ | ||
public setLegacyMode(legacyMode = true): this { | ||
this.legacyMode = legacyMode; | ||
return this; | ||
} | ||
/** | ||
* Perform analysis and retrieve results. *Does not chain.* | ||
@@ -143,3 +157,3 @@ * @return Promise<Result | Error> | ||
if (!runPartialDefined) { | ||
if (!runPartialDefined || this.legacyMode) { | ||
results = await this.runLegacy(context); | ||
@@ -175,8 +189,8 @@ return results; | ||
return ` | ||
${this.source} | ||
axe.configure({ | ||
allowedOrigins: ['<unsafe_all_origins>'], | ||
branding: { application: 'playwright' } | ||
}) | ||
`; | ||
${this.source} | ||
axe.configure({ | ||
${this.legacyMode ? '' : 'allowedOrigins: ["<unsafe_all_origins>"],'} | ||
branding: { application: 'playwright' } | ||
}) | ||
`; | ||
} | ||
@@ -183,0 +197,0 @@ |
@@ -400,2 +400,46 @@ import 'mocha'; | ||
describe('setLegacyMode', () => { | ||
const runPartialThrows = `;axe.runPartial = () => { throw new Error("No runPartial")}`; | ||
it('runs legacy mode when used', async () => { | ||
await page.goto(`${addr}/external/index.html`); | ||
const results = await new AxeBuilder({ | ||
page, | ||
axeSource: axeSource + runPartialThrows | ||
}) | ||
.setLegacyMode() | ||
.analyze(); | ||
assert.isNotNull(results); | ||
}); | ||
it('prevents cross-origin frame testing', async () => { | ||
await page.goto(`${addr}/external/cross-origin.html`); | ||
const results = await new AxeBuilder({ | ||
page, | ||
axeSource: axeSource + runPartialThrows | ||
}) | ||
.withRules('frame-tested') | ||
.setLegacyMode() | ||
.analyze(); | ||
const frameTested = results.incomplete.find( | ||
({ id }) => id === 'frame-tested' | ||
); | ||
assert.ok(frameTested); | ||
}); | ||
it('can be disabled again', async () => { | ||
await page.goto(`${addr}/external/cross-origin.html`); | ||
const results = await new AxeBuilder({ page }) | ||
.withRules('frame-tested') | ||
.setLegacyMode() | ||
.setLegacyMode(false) | ||
.analyze(); | ||
const frameTested = results.incomplete.find( | ||
({ id }) => id === 'frame-tested' | ||
); | ||
assert.isUndefined(frameTested); | ||
}); | ||
}); | ||
describe('for versions without axe.runPartial', () => { | ||
@@ -430,2 +474,17 @@ describe('analyze', () => { | ||
}); | ||
it('tests cross-origin pages', async () => { | ||
await page.goto(`${addr}/external/cross-origin.html`); | ||
const results = await new AxeBuilder({ | ||
page, | ||
axeSource: axeLegacySource | ||
}) | ||
.withRules('frame-tested') | ||
.analyze(); | ||
const frameTested = results.incomplete.find( | ||
({ id }) => id === 'frame-tested' | ||
); | ||
assert.isUndefined(frameTested); | ||
}); | ||
}); | ||
@@ -432,0 +491,0 @@ |
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
91369
1600
155