Skip to content

Commit 792d958

Browse files
committed
feat(build): Add visual diff scripts
Test plan: - Make a visual change to the Alert component and commit it - Run yarn generate:screenshots - Run yarn review:screenshots You should see a visual diff of the changes. Change-Id: Ia53bcadddbd168401ba53dad9d9152e65eb2ac96 Reviewed-on: https://gerrit.instructure.com/147082 Tested-by: Jenkins Reviewed-by: Stephen Jensen <sejensen@instructure.com> Product-Review: Jennifer Stern <jstern@instructure.com> QA-Review: Jennifer Stern <jstern@instructure.com>
1 parent 3841542 commit 792d958

File tree

9 files changed

+417
-12
lines changed

9 files changed

+417
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ package-lock.json
99
__build__
1010
.vscode
1111
stories.asketch.json
12+
__screenshots__
13+
screenshots.json

.happo.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const FirefoxTarget = require('happo-target-firefox')
2+
// const S3Uploader = require('happo-uploader-s3')
3+
4+
module.exports = {
5+
resultSummaryFilename: 'screenshots.json',
6+
7+
// A function that returns an "Uploader" interface for CI.
8+
// (default: null)
9+
// uploader: () => new S3Uploader(),
10+
11+
snapshotsFolder: '__screenshots__',
12+
13+
targets: [
14+
new FirefoxTarget({
15+
sourceFiles: ['.happo/__build__/config.js']
16+
})
17+
]
18+
}

.happo/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@instructure/ui-presets/babel", { themeable: true }]]
3+
}

.happo/config.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import React from 'react'
26+
import { render, unmountComponentAtNode } from 'react-dom'
27+
import path from 'path'
28+
29+
import '@instructure/ui-themes/lib/canvas'
30+
31+
/* global happo */
32+
33+
const TESTS = []
34+
35+
// Automatically import all component .examples.js files in packages
36+
const requireExamples = require.context('../packages', true, /src\/\S+\.examples\.js$/)
37+
38+
// assemble the tests from the examples
39+
requireExamples.keys()
40+
.forEach((pathToExamples) => {
41+
const componentName = path.basename(pathToExamples, '.js').replace('.examples', '')
42+
const componentExamples = requireExamples(pathToExamples)
43+
44+
Object.keys(componentExamples)
45+
.forEach((exampleName) => {
46+
TESTS.push({
47+
component: componentName,
48+
name: exampleName,
49+
Example: componentExamples[exampleName]
50+
})
51+
})
52+
})
53+
54+
// define the tests
55+
TESTS.forEach((test) => {
56+
const { Example, component, name } = test
57+
happo.define(
58+
`<${component}/>: ${name}`,
59+
() => {
60+
const div = document.createElement('div')
61+
document.body.appendChild(div)
62+
render(<Example />, div)
63+
},
64+
{ viewports: ['large', 'medium', 'small'] }
65+
)
66+
})
67+
68+
happo.cleanOutElement = function (element) {
69+
unmountComponentAtNode(element)
70+
}
71+
72+
happo.getRootNodes = function () {
73+
return document.querySelectorAll('[data-reactroot]')
74+
}

.happo/webpack.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
const path = require('path')
26+
27+
module.exports = {
28+
entry: {
29+
config: path.resolve(__dirname, 'config.js')
30+
},
31+
output: {
32+
path: path.resolve(__dirname, '__build__'),
33+
filename: '[name].js'
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.js$/,
39+
exclude: /node_modules/,
40+
loader: 'babel-loader'
41+
}
42+
]
43+
}
44+
}

.storybook/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ setOptions({
88
name: "Instructure UI",
99
url: "http://instructure.github.io/instructure-ui/#index",
1010
goFullScreen: false,
11-
showLeftPanel: true,
12-
showDownPanel: false,
11+
showStoriesPanel: true,
12+
showAddonPanel: false,
1313
showSearchBox: false
1414
})
1515

16-
// automatically import all files ending in *.stories.js from the src folders
16+
// automatically import all stories.js files in the packages
1717
const req = require.context('../packages', true, /stories\.js$/)
1818

1919
function loadStories() {

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
"predeploy": "yarn build:docs",
4444
"deploy": "lerna run deploy",
4545
"storybook": "start-storybook -p 9001 -c .storybook",
46-
"generate:sketch": "story2sketch --url http://localhost:9001/iframe.html --output stories.asketch.json"
46+
"generate:sketch": "story2sketch --url http://localhost:9001/iframe.html --output stories.asketch.json",
47+
"build:examples": "webpack --config .happo/webpack.config.js",
48+
"generate:screenshots": "./scripts/screenshots",
49+
"review:screenshots": "happo review"
4750
},
4851
"license": "MIT",
4952
"devDependencies": {
@@ -52,9 +55,13 @@
5255
"@storybook/addon-options": "^3.3.15",
5356
"@storybook/react": "^3.4.1",
5457
"commitizen": "2.9.6",
58+
"happo": "^5.0.0",
59+
"happo-target-firefox": "^5.0.0",
5560
"lerna": "2.9.0",
5661
"lint-staged": "^6.1.0",
5762
"npm-run-all": "4.1.2",
63+
"react": "15.6.2",
64+
"react-dom": "15.6.2",
5865
"standard-version": "4.3.0",
5966
"story2sketch": "^0.2.1",
6067
"validate-commit-msg": "2.14.0",

scripts/screenshots

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -ex
2+
3+
NPM_CLIENT=$(npm bin)/yarn
4+
5+
run-happo() {
6+
git checkout --quiet $1
7+
8+
$NPM_CLIENT run build:examples
9+
10+
happo run
11+
}
12+
13+
# Check out the previous version and generate snapshots
14+
run-happo HEAD^
15+
16+
# Check out the latest version and check for diffs
17+
run-happo -

0 commit comments

Comments
 (0)