Chasing The Dream of Style Guide Driven Development
One tiny css change causes a regression deep in the outer reaches of your site
(and, it goes unnoticed for lord knows how long)
Base Themes
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
]
%}
< div {{ attributes.addClass(classes) }}>
(From block.html.twig)
{% if attributes.hasClass('myClass') %}
{# do stuff #}
{% endif %}
Naming convention for components
.block {}
.block__element {}
.block--modifier {}
.block__element--modifier {}
field.html.twig
Custom field.html.twig
field--field-hero-header.html.twig
hook_styleguide()
hook_styleguide_alter()
https://www.drupal.org/node/2606942
Many options
(There's a module for that...)
npm install kss --save-dev
npm install grunt-kss --save-dev
// Solution Teaser
//
// A teaser for solutions taxonomy as displayed on the homepage
//
// Markup: kss_markup/solution_teaser.html
//
// Style Guide: Solutions.Teaser
.view-solutions .views-row {
.views-field-field-category-icon .col-xs-3 {
padding: 3%;
border-radius: 50%;
background-color: $gray_light;
img {
@extend .img-responsive;
}
}
}
grunt kss
or:
kss-node --source sass --destination styleguide --css css/style.css
Behavior Driven Development Framework
@javascript
Scenario: Footer style matches style guide
Given I am an anonymous user
And I am on "assessments/practice-assessments"
When I am browsing using a "phone"
Then "body" should have a "background-color" css value of "rgb(112, 84, 125)"
And "#page" should have a "background-color" css value of "rgb(255, 255, 255)"
And "footer" should have a "padding-top" css value of "50px"
And "footer" should have a "padding-bottom" css value of "30px"
View Gist for detail of steps
Screenshot Comparison Tool
CSS Regression Testing
Strengths: interactivity, easier to target components.
Selenium Bindings for NodeJS
Strengths: interactivity, easier to target components.
npm install webdriverio@3.4.0 webdrivercss@2.0.0beta-rc1 selenium-standalone --save-dev
./node-modules/.bin/selenium-standalone install
wdio-tests.js
var wdio = require("webdriverio");
var webdrivercss = require("webdrivercss");
var assert = require("assert");
var options = {
desiredCapabilities: {
browserName: "chrome"
}
}
var browser = wdio.remote(options);
webdrivercss.init(browser, {
screenshotRoot: "screenshots"
});
function assertShots (err, shots) {
assert.ifError(err);
Object.keys(shots).forEach(function(element) {
shots[element].forEach(function(shot) {
assert.ok(shot.isWithinMisMatchTolerance, shot.message);
})
});
};
browser
.init()
.url("http://breaktech.dev.dd:8083/")
.webdrivercss("solutions", [
{
name: "solution teaser",
elem: ".view-solutions .views-row:first-child"
}
], assertShots)
.click(".fa-bars")
.webdrivercss("navigation", [
{
name: "Off Canvas Menu",
elem: ".sidebar-offcanvas"
}
], assertShots)
.end();
https://www.drupal.org/node/2702061
drupaltwig.slack.com #components