CSS regression testing

Presented by Sergey Semashko

CSS is easy to change...

Unintended consicuences to # of devs graph

... and hard to test

Approaches to test CSS

  1. Syntax checks
  2. Styleguides & linting
  3. Comparing screenshots
  4. Comparing styles in DOM

Syntax checks

Syntax checks
Syntax checks

Styleguides & linting


@import "other.css";
div {
    padding: 0px 10px;
}
                        
Css lint
Css lint errors
  • Prevents anti-patterns
  • Easy to apply
  • Doesn't test end result
  • Useless without good linting rules

Comparing Screenshots

Image diff example

Tools

  • No changes can sneak by
  • Content-fragile

Comparing styles in DOM


  window.getComputedStyle();
                    

Hardy / Cucumber


Scenario: Standard paragraph color
  Given I visit "http://local.gemini.com/about.html"
  Then ".container > p" should have
    "color" of "rgb(64, 64, 64)"
                    

Tools

  • Resilient to changes
  • Reduces unintended consequences
  • Writing expectations in code
  • Style rules != look
  • Structure-fragile

There is no "silver bullet",
yet.

THE END