Skip to content

Commit

Permalink
test: add visual regression tests (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Sep 12, 2020
1 parent 2cd4fc2 commit 08fd3b6
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -13,3 +13,4 @@ script:
- npm run size
- npm run lint
- npm test
- npm run test:visual
101 changes: 101 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -50,7 +50,9 @@
"size": "npm run build && size-limit",
"start": "web-dev-server --app-index dist/index.html --open",
"styles": "node ./scripts/build-styles.js",
"test": "wtr src/test/*.ts",
"test": "wtr src/test/*.ts --coverage",
"test:visual": "wtr src/test/visual/*.ts",
"test:update": "UPDATE_REFS=true wtr src/test/visual/*.ts",
"watch": "tsc-watch"
},
"husky": {
Expand Down Expand Up @@ -101,13 +103,14 @@
"@open-wc/testing-helpers": "~1.7.2",
"@rollup/plugin-node-resolve": "^9.0.0",
"@size-limit/preset-small-lib": "^4.5.7",
"@types/sinon": "^9.0.5",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"@types/sinon": "^9.0.5",
"@web/dev-server-esbuild": "^0.2.4",
"@web/dev-server": "^0.0.5",
"@web/dev-server-esbuild": "^0.2.4",
"@web/rollup-plugin-copy": "^0.1.1",
"@web/test-runner": "^0.7.17",
"@web/test-runner-visual-regression": "^0.1.5",
"eslint": "^7.8.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/test/visual/visual.test.ts
@@ -0,0 +1,28 @@
import { visualDiff } from '@web/test-runner-visual-regression';
import { fixture } from '@open-wc/testing-helpers';
import '../../hex-color-picker.js';
import '../../hsl-color-picker.js';
import '../../hsl-string-color-picker.js';
import '../../hsv-color-picker.js';
import '../../rgb-color-picker.js';
import '../../rgb-string-color-picker.js';

describe('visual tests', () => {
let picker: HTMLElement;

['hex', 'hsl', 'hsl-string', 'hsv', 'rgb', 'rgb-string'].forEach((type) => {
describe(`${type}-color-picker`, () => {
beforeEach(async () => {
picker = await fixture(`
<div style="display: flex; justify-content: center; width: 216px; padding: 8px">
<${type}-color-picker></${type}-color-picker>
</div>
`);
});

it('should match screenshot', async () => {
await visualDiff(picker, type);
});
});
});
});
10 changes: 8 additions & 2 deletions web-test-runner.config.js
@@ -1,9 +1,15 @@
const { esbuildPlugin } = require('@web/dev-server-esbuild');
const { visualRegressionPlugin } = require('@web/test-runner-visual-regression/plugin');

module.exports = {
nodeResolve: true,
plugins: [esbuildPlugin({ ts: true })],
coverage: true,
plugins: [
esbuildPlugin({ ts: true }),
visualRegressionPlugin({
baseDir: 'src/test/visual/screenshots',
update: process.env.UPDATE_REFS === 'true'
})
],
coverageConfig: {
threshold: {
statements: 99,
Expand Down

0 comments on commit 08fd3b6

Please sign in to comment.