Lesson 49 of 50
cssCSS Testing – Visual Regression & Linting
8 mins
Course progress98%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 49 of 50
css8 mins
Keep these ideas in mind as you work through the lesson.
Testing CSS ensures consistency, standards compliance, and maintainability across the team.
.stylelintrc.json{
"extends": "stylelint-config-standard",
"plugins": ["stylelint-order"],
"rules": {
"color-no-invalid-hex": true,
"max-nesting-depth": 3,
"order/order": [
"custom-properties",
"declarations"
]
}
}
npm run lint:css.npm install -g backstopjs
backstop init # creates config
backstop test # runs visual regression
npx axe) or browser extension.npm run test:axe).name: CSS CI
on: [push, pull_request]
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install deps
run: npm ci
- name: Lint CSS
run: npm run lint:css
- name: Visual Regression (Backstop)
run: npm run backstop:test
/tests/baselines). Commit them to version control; when a UI change is intentional, update the baseline with backstop approve.alt attributes; otherwise visual diff tools can’t verify semantics.stylelint locally – fix any warnings.backstop test).| Symptom | Cause | Fix |
|---|---|---|
| Random failures on CI | Different device pixel ratio (DPR) affecting screenshots. | Set --web-push --chromeFlags="--force-device-scale-factor=1" in Backstop config. |
| Lint errors on vendor prefixes | autoprefixer adds prefixes that the linter flags as unknown. | Add "ignore: ['-webkit-']" rule or run lint after autoprefixing. |
Combining automated linting with visual regression gives you a safety net: the linter catches syntax and convention bugs, while visual diff catches appearance regressions that static analysis can’t see.