Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Add visual regression testing and a11y testing with Pa11y
Browse files Browse the repository at this point in the history
  • Loading branch information
onishiweb committed May 3, 2019
1 parent 93f709a commit 625e133
Show file tree
Hide file tree
Showing 11 changed files with 1,505 additions and 13 deletions.
13 changes: 11 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"presets": [
"@babel/preset-env", "@babel/preset-react"
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": ["babel-plugin-styled-components"]
"plugins": [
"babel-plugin-styled-components",
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
}
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Built files
dist

# Node modules
node_modules
src/__snapshots__

# Testing output
coverage/
src/__snapshots__
__tests__/__snapshots__
__tests__/__image_snapshots__
8 changes: 8 additions & 0 deletions .pa11yci
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaults": {
"timeout": 5000
},
"urls": [
"http://localhost:8080"
]
}
24 changes: 24 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env jest */
import { setup, teardown, getFile } from '../jest/test.utils'

let chromeless = null

beforeAll(() => { chromeless = setup() })
afterAll(async () => { await teardown(chromeless) })

test('+++ home renders correctly (visual)', async () => {
const screenshotPath = await chromeless.goto(global.config.baseUrl).wait('button').screenshot()
const screenshot = await getFile(screenshotPath)
const customDiffConfig = {
composeLeftToRight: true,
}
expect(screenshot).toMatchImageSnapshot({ customDiffConfig })
})

test('+++ home renders correctly', async () => {
const html = await chromeless
.goto(global.config.baseUrl)
.wait('button')
.evaluate(() => document.querySelector('button').innerHTML)
expect(html).toMatchSnapshot()
})
6 changes: 6 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global.config = {
chromeless: {
launch: false,
},
baseUrl: 'http://localhost:8080',
}
42 changes: 42 additions & 0 deletions jest/test.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env jest */
import { Chromeless } from 'chromeless'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import * as fs from 'fs'
import request from 'request'

export const setup = () => {
jest.setTimeout(10000)
expect.extend({ toMatchImageSnapshot })
return new Chromeless(global.config.chromeless)
}

export const teardown = async chromeless => {
try {
await chromeless.end()
} catch (err) {
console.log(err)
}
}

const download = uri =>
new Promise((resolve, reject) => {
request(
{
url: uri,
method: 'GET',
encoding: null,
},
(error, response, body) => {
if (!error && response.statusCode === 200) {
resolve(body)
} else {
reject(error)
}
},
)
})

export const getFile = path => (path.startsWith('https://')
? download(path)
: Promise.resolve(fs.readFileSync(path))
)
Loading

0 comments on commit 625e133

Please sign in to comment.