-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from esteban-serfe/junit-reporter
Added initial report junit generator
- Loading branch information
Showing
6 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Reporter from '../types' | ||
import { Result } from 'axe-core' | ||
import { Page } from 'playwright' | ||
import builder from 'junit-report-builder'; | ||
import pc from 'picocolors' | ||
import assert from 'assert' | ||
|
||
export default class JUnitReporter implements Reporter { | ||
constructor( | ||
protected verbose: boolean | undefined, | ||
protected page: Page | undefined, | ||
protected outputFilename: string | undefined | ||
) { | ||
|
||
} | ||
|
||
async report(violations: Result[]) : Promise<void> { | ||
let lineBreak = '\n'; | ||
let pageUrl = this.page?.url() || 'Page'; | ||
let suite = builder.testSuite().name(pageUrl); | ||
|
||
const message = | ||
violations.length === 0 | ||
? 'No accessibility violations detected!' | ||
: `Found ${violations.length} accessibility violations` | ||
|
||
violations | ||
.map((violation) => { | ||
|
||
const errorBody = violation.nodes | ||
.map((node) => { | ||
const selector = node.target.join(', ') | ||
const expectedText = | ||
`Expected the HTML found at $('${selector}') to have no violations:` + | ||
'\n' | ||
return ( | ||
expectedText + | ||
node.html + | ||
lineBreak + | ||
`Received:\n` + | ||
`${violation.help} (${violation.id})` + | ||
lineBreak + | ||
node.failureSummary + | ||
lineBreak + | ||
(violation.helpUrl | ||
? `You can find more information on this issue here: \n${violation.helpUrl}` | ||
: '') + | ||
'\n' | ||
) | ||
}) | ||
.join(lineBreak) | ||
|
||
suite.testCase().className(violation.id).name(violation.description).failure(errorBody) | ||
}) | ||
|
||
const pass = violations.length === 0 | ||
|
||
if (pass) { | ||
builder.testCase().name("Accesibility testing - A11Y"); | ||
this.verbose && console.log(`No accessibility violations detected!`) | ||
} | ||
let location = this.outputFilename || 'a11y-tests.xml'; | ||
builder.writeTo(location); | ||
|
||
if (!pass) { | ||
assert.fail(message) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters