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

@forsakringskassan/cypress-axe

v3.1.1

Published

Axe injector and executor at the end of cypress tests

Downloads

125

Readme

@forsakringskassan/cypress-axe

Ett cypress plugin för att automatiskt köra axe tester.

Plugin:et placerar och utför valideringskontroller för tillgänglighet i slutet av varje cypress test.

Installation / Användning

Plugin:et placerar automatiskt diverse valideringscheckar efter varje cypress mha. ett vanligt afterEach block i Cypress. För att injicera samt konfigurera plugin:et på rätt sätt krävs att man lägger till följande kodstycken i sin support/index.js samt plugins/index.js.

Om man har cypress-axe sen tidigare tar man bort det, kolla i:

  • package.json
  • support/index.js
  • plugins/index.js

support/index.js

Lägg till följande någonstans i filen

import "fk-cypress-axe/support";

plugins/index.js

Lägg till följande i toppen av filen

const fkcyaxe = require("fk-cypress-axe/plugins");

Om det inte redan finns en module.exports = (on, config) => { ... } pilfunktion, lägg då till denna. Notera att både on och config behövs.

config = fkcyaxe.init(on, config);

Ovanstående rad modifierar cypress konfigurationen, därför är det sedan också viktigt att pilfunktionen returnerar det slutgiltiga config objektet

return config;

Filen kan exempelvis då se ut som följande:

const fkcyaxe = require("fk-cypress-axe/plugins");

module.exports = (on, config) => {
    // ...

    config = fkcyaxe.init(on, config);

    // ...

    return config;
};

Konfiguration

Konfigurationen av plugin:et görs i fk-cypress-axe.json i root-katalogen.

Basinställningarna ser ut som följande:

{
  "axe": {
    "rules": [
      // Disable color contrast rule
      {
        "id": 'color-contrast',
        "enabled": false,
      },
    ],
  },
  "context": null,
  "assertOnViolation": true, // Stoppar resterande tester så fort ett misslyckas. (Annars rapporteras även felaktiga testfall som lyckade).
  "displayHelpUrl": true, // Visar aXe help URL tillsammans med felet. Default true.
  "displayContext": true, // Visar sammanhang (CSS selector, HTML, Förslag till rättelse, osv.)
  "displayPasses": true, // Visar även passes. Default true
  "displayViolations": true, // Visar felen. Default true.
  "standardsToReport": ['wcag2a', 'wcag2aa'], // Lista med standarder som kontrolleras. Om listan är tom visas valideras samtliga standarder.
  "ignoreAxeFailures": false, // Ignorera Axe-valideringsfel. Default false
  "displayWhen": 'both', // När felen ska visas ("immediate", "end", "both")
  "excludeSelectorsList": [], // Lista med eventuella CSS selectorer som ska undantas från tillgänglighetskontrollerna
}

Genom att fylla i en lokal fk-cypress-axe.json kan man alltså skriva över enskilda inställningar i denna filen. Resterande fält diff:as mot basinställningarna.

OBS: Vissa inställningar diff:as ej, nämligen inställningarna som finns i axe.rules. Dvs. om man i sin lokala konfiguration ändrar 'color-contrast' regeln på något sätt så kommer enabled att återställas till true, även om man själv inte ändrat just enabled.

include / exclude

Utöver excludeSelectorsList kan man använda context för att ange vad som ska inkluderas och exkluderas. Detta påverkar vilka element som axe kör på iställer för filtrering i efterhand.

fk-cypress-axe.json:

{
    "context": {
        "include": [["#app"]],
        "exclude": [[".selector1"], [".selector2"], ["..."]]
    }
}

Filspecifik konfiguration

Det är möjligt att ändra konfigurationen för en enskild fil. Dessa ändringar kommer alltså inte att sprida sig till övriga .spec filer. Detta görs genom att tidigt i spec filen lägga till följande kodstycke.

before(() => {
    // Retrieves the current configuration used by fk-cypress-axe.
    cy.getAxeConfigThisFile().then((config) => {
        // Make your changes here, for example, the following is a valid change
        config.excludeSelectorsList = [".secret-menu"];

        // Don't forget to pass your changed config back to cypress
        cy.setAxeConfigThisFile(config);
    });
});

Det är för tillfället inte möjligt att ändra konfigurationen för enskilda testfall. Ovanstående stycke kommer att påverka hela .spec filen fr.o.m då det körs. Det finns därför ingen mening med att placera det på annan plats än i det yttersta scope:t.