Skip to content

Commit a1616de

Browse files
authored
test: capture screenshots with capture-chrome, and diff them with resemble (material-components#3)
1 parent 8264c48 commit a1616de

19 files changed

+333
-11
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
]
5+
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage
2+
.idea
23
node_modules
3-
.DS_Store
4+
.DS_Store

package-lock.json

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"license": "Apache-2.0",
55
"scripts": {
66
"start": "webpack-dev-server --config test/screenshot/webpack.config.js --content-base test/screenshot",
7+
"stop": "./test/screenshot/stop.sh",
8+
"capture": "./node_modules/.bin/mocha --compilers js:babel-core/register --ui tdd test/screenshot/capture-suite.js",
79
"commitmsg": "validate-commit-msg",
810
"fix": "eslint --fix packages test",
911
"lint": "eslint packages test",
10-
"pretest": "npm run lint",
11-
"test": "npm run test:unit",
12-
"posttest": "istanbul report --root coverage text-summary && istanbul check-coverage --lines 95 --statements 95 --branches 95 --functions 95",
12+
"pretest": "npm run lint && npm stop && ./test/screenshot/start.sh",
13+
"test": "npm run test:unit && npm run test:image-diff",
14+
"posttest": "npm stop && istanbul report --root coverage text-summary && istanbul check-coverage --lines 95 --statements 95 --branches 95 --functions 95",
1315
"test:watch": "karma start --auto-watch",
14-
"test:unit": "karma start --single-run"
16+
"test:unit": "karma start --single-run",
17+
"test:image-diff": "./node_modules/.bin/mocha --compilers js:babel-core/register --ui tdd --timeout 15000 test/screenshot/diff-suite.js"
1518
},
1619
"config": {
1720
"validate-commit-msg": {
@@ -28,12 +31,14 @@
2831
"babel-loader": "^7.1.4",
2932
"babel-preset-es2015": "^6.24.1",
3033
"babel-preset-react": "^6.24.1",
34+
"capture-chrome": "^2.0.0",
3135
"chai": "^4.1.2",
3236
"css-loader": "^0.28.10",
3337
"eslint": "^3.19.0",
3438
"eslint-config-google": "^0.9.1",
3539
"eslint-plugin-react": "^7.7.0",
3640
"extract-text-webpack-plugin": "^3.0.2",
41+
"fs-readfile-promise": "^3.0.1",
3742
"husky": "^0.14.3",
3843
"istanbul": "^0.4.5",
3944
"istanbul-instrumenter-loader": "^3.0.0",
@@ -43,6 +48,7 @@
4348
"karma-mocha": "^1.3.0",
4449
"karma-webpack": "^2.0.13",
4550
"mocha": "^5.0.2",
51+
"node-resemble-js": "^0.2.0",
4652
"node-sass": "^4.7.2",
4753
"optimize-css-assets-webpack-plugin": "^3.2.0",
4854
"react": "^16.2.0",

test/screenshot/capture-suite.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import fullSuite from './full-suite';
2+
3+
fullSuite.forEach((screenshotSuite) => {
4+
screenshotSuite.capture();
5+
});

test/screenshot/diff-suite.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import fullSuite from './full-suite';
2+
3+
fullSuite.forEach((screenshotSuite) => {
4+
screenshotSuite.diff();
5+
});

test/screenshot/full-suite.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import temporaryPackageSuite from './temporary-package/screenshot-suite';
2+
3+
const fullSuite = [
4+
temporaryPackageSuite,
5+
];
6+
7+
export default fullSuite;

test/screenshot/screenshot-suite.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default class ScreenshotSuite {
2+
constructor(name, screenshots) {
3+
this.name_ = name;
4+
this.screenshots_ = screenshots;
5+
}
6+
7+
capture() {
8+
suite(this.name_, () => {});
9+
10+
this.screenshots_.forEach((screenshot) => {
11+
screenshot.capture();
12+
});
13+
}
14+
15+
diff() {
16+
suite(this.name_, () => {});
17+
18+
this.screenshots_.forEach((screenshot) => {
19+
screenshot.diff();
20+
});
21+
}
22+
}

0 commit comments

Comments
 (0)