GitXplorerGitXplorer
l

cypress-forced-colors

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
4ccc8ababf473bfd2954232bac5a993e9748d4ba

Release 1.0.2

lling1726 committed 3 years ago
Unverified
d8da5d6e30d401859498da1cf9827eb70bf23fd9

fix published files

lling1726 committed 3 years ago
Unverified
4ff1cf2df2b8457f7a919c19d98482f9d8fafe1a

Release 1.0.1

lling1726 committed 3 years ago
Verified
3b6ec789291284da5161c4e559d586d2c540e1bc

Merge pull request #2 from ling1726/fix/release

lling1726 committed 3 years ago
Unverified
7cd747230d5a60c1790b40de35e3e521adde8dc9

prepublish step

lling1726 committed 3 years ago
Unverified
8dbc3e8e2490c4b26af574cfc64b5bff54bfd0f9

Add release steps

lling1726 committed 3 years ago

README

The README file for this repository.

Cypress Forced Colors

⚠️ For full forced color emulation, the browser you are testing on must be Chromium > 98.

This library contains helper cypress methods to enable and disable forced colors emulation in chromium borwsers through the chrome devtools protocol.

The devtools APIs used by this library can be found on the official chrome devtools protocol docs.

Why

Forced colors is a browser mode where color CSS properties are overriden. You can find a full list of affected properties on the MDN docs. This browser feature is leveraged notably by Windows High Contrast Mode, which will override all colors with system colors to provide more contrast for users that need it.

Chrome devtools has media emulation as a stable feature and in version 98, supports full emulation of forced colors. This plugin can be used to have an easy way of testing acessible high contrast designs without needing a windows machine or enabling a windows os feature.

Installation

npm install --save-dev cypress-forced-colors

Setup

Add the following code to your cypress support file.

// cypress/support/index.js
// cypress/support/index.ts

import 'cypress-forced-colors';

Usage

Once the custom commands are registered with cypress you can enable or disable forced color mode in your tests.

it('Test with forced colors mode', () => {
  cy.enableForcedColors('dark');

  // your test code...

  cy.disableForcedColors();
})

You can also use this for test suites

describe('Forced color tests', () => {
  before(() => {
    cy.enableForcedColors('dark');
  });

  after(() => {
    cy.disableForcedColors();
  })
})

Try it out!

⚠️ Make sure you use a Chromium browser with version > 98

You can try out this feature from this repository. Simply clone the repo and run the following commands to open cypress and test to see the example test suite.

npm install
npm start