npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

axe-html-reporter

v2.2.11

Published

The module that allows you to create HTML Report from raw accessibility aXe result object

Downloads

1,738,656

Readme

axe-html-reporter

Creates an HTML report from Axe-core® library AxeResults object listing violations, passes, incomplete and incompatible results.

Allows specifying report creation options: reportFileName, outputDir, outputDirPath, projectKey and customSummary.

Notes:

  • customSummary allows having html parameters
  • outputDirPath allows specifying absolute path

Please check sample report output.

createHtmlReport returns HTML content that can be additionally used for specific integrations.

If only HTML content needed, user can pass doNotCreateReportFile: true to stop report file creation.

Suggestion on how to use this library if you don't need a report file but need only HTML it produces:

const reportHTML = createHtmlReport({
    results: rawAxeResults,
    options: {
        projectKey: 'I need only raw HTML',
        doNotCreateReportFile: true,
    },
});
console.log('reportHTML will have full content of HTML file.');
// suggestion on how to create file by yourself
if (!fs.existsSync('build/reports/saveReportHere.html')) {
    fs.mkdirSync('build/reports', {
        recursive: true,
    });
}
fs.writeFileSync('build/reports/saveReportHere.html', reportHTML);

Install

npm i -D axe-html-reporter

Usage

Example usage in TestCafe

To run TestCafe tests with Axe-core®, install testcafe, axe-core and @testcafe-community/axe:

npm i -D axe-html-reporter testcafe axe-core @testcafe-community/axe

For TestCafe example add the following clientScript in your .testcaferc.json config:

{
    "clientScripts": [{ "module": "axe-core/axe.min.js" }]
}

In the example bellow fileName is not passed. If fileName is not passed, HTML report will be created with default name accessibilityReport.html in artifacts directory.

See full TestCafe test example is bellow:

import { runAxe } from '@testcafe-community/axe';
import { createHtmlReport } from 'axe-html-reporter';

fixture('TestCafe tests with Axe-core®').page('http://example.com');

test('Automated accessibility testing', async (t) => {
    const axeContext = { exclude: [['select']] };
    const axeOptions = {
        rules: {
            'object-alt': { enabled: true },
            'role-img-alt': { enabled: true },
            'input-image-alt': { enabled: true },
            'image-alt': { enabled: true },
        },
    };
    const { error, results } = await runAxe(axeContext, axeOptions);
    await t.expect(error).notOk(`axe check failed with an error: ${error.message}`);
    // creates html report with the default file name `accessibilityReport.html`
    createHtmlReport({
        results,
        options: {
            projectKey: 'EXAMPLE',
        },
    });
});

Run TestCafe test:

npx testcafe
 Running tests in:
 - Chrome 85.0.4183.121 / Linux

 TestCafe tests with Axe-core®
HTML report was saved into the following directory /Users/axe-demos/artifacts/accessibilityReport.html
 ✓ Automated accessibility testing


 1 passed (1s)

Example usage in any JS framework

import { createHtmlReport } from 'axe-html-reporter';

(() => {
    // creates html report with the default name `accessibilityReport.html` file
    createHtmlReport({ results: 'AxeCoreResults' }); // full AxeResults object
    // creates html report with the default name `accessibilityReport.html` file and all supported AxeResults values
    createHtmlReport({ results: { violations: 'Result[]' } }); // passing only violations from axe.run output
    // creates html report with the default name `accessibilityReport.html` file and adds url and projectKey
    createHtmlReport({
        results: 'AxeCoreResults',
        options: { projectKey: 'JIRA_PROJECT_KEY' },
    });
    // creates html report with the name `exampleReport.html` in 'axe-reports' directory and adds projectKey to the header
    createHtmlReport({
        results: 'AxeCoreResults',
        options: {
            projectKey: 'JIRA_PROJECT_KEY',
            outputDir: 'axe-core-reports',
            reportFileName: 'exampleReport.html',
        },
    });
    // creates html report with all optional parameters, saving the report into 'docs' directory with report file name 'index.html'
    const customSummary = `Test Case: Full page analysis
    <br>Steps:</br>
    <ol style="margin: 0">
    <li>Open https://dequeuniversity.com/demo/mars/</li>
    <li>Analyze full page with all rules enabled</li>
    </ol>`;
    createHtmlReport({
        results: 'AxeResults',
        options: {
            projectKey: 'DEQUE',
            customSummary,
            outputDir: 'docs',
            reportFileName: 'index.html',
        },
    });
})();

CommonJS

const { createHtmlReport } = require('axe-html-reporter');

(() => {
    // creates html report with the name `accessibilityReport.html` file
    createHtmlReport({ results: { violations: 'Result[]' } });
})();