Wait...So I have to test the front end too?
Wait...So I have to test the front end too?
I'm a freelance front end developer based in Perth, which means I spend most of my time at the beach and the rest
of it working from home in my pyjamas
I'm also heavily involved in the Perth tech community, help run a user group for front end
developers, am on the committee for the DDD Perth conference, attend all the Perth tech meetups and
work as an evangelist for YOW conferences
Last year I also became a Twilio champion and a Microsoft MVP
I also have a beautiful grey and white border collie who sits next to me wherever I'm working from
home
And although he's enjoyed having me home, honestly I think he's really wanting to have some alone time
Wait...So I have to test the front end too?
But today I'm here to talk about testing
Why test?
We all know that testing is important, that's never a question
Although there is a lot of debate about whether you should write your code or your tests first
We even have a software process, test driven development, centred around tests
What about the front end?
But despite all those strong opinions
We often don't hear about what's happening on the front end
The front end matters too
There are so many different tests we need to be running on the front end
Accessibility testing
Performance testing
User testing
HTML validation
Visual Regression testing
Accessibility testing, performance testing, user testing, HTML validation, visual regression
testing
It's often hard to work out what you need to test for and where to start
So I'm a testing expert?
No.
So if I'm standing up here telling you how to do this, it must mean I'm an expert?
Last year, the only testing I could do was running the cypress npm script for a project with
pre-written tests
So why me?
I've only just gone through the process of learning to test
Coming with no prior knowledge
Linting
Ok, not technically testing
Automated checking for programmatic and stylistic errors
Type of automated check
Happens early in development
Checks for (and sometimes fixes) small stylistic errors
These tools can both be run via the command line
Or depending on your IDE or or deployment pipeline you can run them through there
https://eslint.org/docs/rules
https://stylelint.io/user-guide/rules
Accessibility Testing
Validating HTML
Checking for alt tags
Colour Contrast
Screen readers and reader modes
Google Home and voice assistants
Web Content Accessibility GuidelinesWCAG
Tests against the web content accessibility Guidelines
https://www.w3.org/WAI/standards-guidelines/wcag
https://pa11y.org
"code" : "wcag2aa.principle1.guideline1_1.1_1_1.h37" ,
"type" : "error" ,
"typecode" : 1 ,
"message" : "img element missing an alt attribute. use the alt attribute to specify a short text alternative." ,
"context" : "<img src=" \"/img/rottnest-lighthouse-2500.jpg\"" >",
" selector": " html > body > header > img",
" runner": " htmlcs",
" runnerextras": {}
"code" : "wcag2aa.principle1.guideline1_1.1_1_1.h37" ,
"type" : "error" ,
"typecode" : 1 ,
"message" : "img element missing an alt attribute. use the alt attribute to specify a short text alternative." ,
"context" : "<img src=" \"/img/rottnest-lighthouse-2500.jpg\"" >",
" selector": " html > body > header > img",
"context" : "<img src=" \"/img/rottnest-lighthouse-2500.jpg\"" >",
" selector": " html > body > header > img",
"code" : "wcag2aa.principle1.guideline1_1.1_1_1.h37" ,
"message" : "img element missing an alt attribute. use the alt attribute to specify a short text alternative." ,
http://squizlabs.github.io/HTML_CodeSniffer/Standards/WCAG2/
pa11y('http://my-testing-blog.local' , {
actions : [
'click element #tab-1' ,
'wait for element #tab-1-content to be visible' ,
],
viewport : {
width : 320 ,
height : 480 ,
ismobile : true
},
standard : 'wcag2aaa' ,
headers : {
'content-type' : 'application/json'
},
method : 'post' ,
postdata : '{"foo": "bar", "bar": "baz"}'
});
await Promise .all([
pa11y(`http://my-testing-blog.local` , options),
])
await Promise .all([
pa11y(`http://my-testing-blog.local` , options),
pa11y(`http://my-testing-blog.local/blog-post` , options)
])
Visual Regression Testing
Screenshots of app
Compares old to new
Visual equivalent of git diffs
npm install -g backstopjs
Can yield false results
Visual regression tests pixel perfect
Can yield failures where it's ok
Eg if images haven't loaded in properly yet
https://github.com/garris/BackstopJS
Can change the threshold to allow minor changes
Linting ✅
Accessibility Testing ✅
Visual Regression Testing ✅
https://youtu.be/DHPX2ShCxBc
https://24ways.org/2019/twelve-days-of-front-end-testing/
https://www.javascriptjanuary.com/blog/getting-started-with-front-end-testing
kapers.dev/fender-test-sydney-2020