Skip to content

Instantly share code, notes, and snippets.

@mjhenkes
Created May 31, 2018 19:25
Show Gist options
  • Select an option

  • Save mjhenkes/d901aa444aaf153937888cfb521dff1f to your computer and use it in GitHub Desktop.

Select an option

Save mjhenkes/d901aa444aaf153937888cfb521dff1f to your computer and use it in GitHub Desktop.
const defaultConfig = require('terra-dev-site/config/wdio/wdio.conf');
const { LocalCompare } = require('wdio-visual-regression-service/compare');
const path = require('path');
const webpackConfig = require('./webpack.config');
const testIdRegex = /\[([^)]+)\]/;
function testName(parent, title) {
const matches = testIdRegex.exec(title);
const parentName = parent.replace(/[\s+.]/g, '_');
let name = title.trim().replace(/[\s+.]/g, '_');
if (matches) {
name = matches[1];
}
return `${parentName}[${name}]`;
}
function getScreenshotName(ref) {
return (context) => {
const browserName = context.desiredCapabilities.browserName;
const browserWidth = context.meta.viewport.width;
const browserHeight = context.meta.viewport.height;
const testPath = path.dirname(context.test.file).replace('node_modules', 'test');
const name = testName(context.test.parent, context.test.title);
return path.join(testPath, '__snapshots__', ref, browserName, `${name}.${browserWidth}x${browserHeight}.png`);
};
}
const visualRegressionConfig = {
compare: new LocalCompare({
referenceName: getScreenshotName('reference'),
screenshotName: getScreenshotName('screen'),
diffName: getScreenshotName('diff'),
misMatchTolerance: 0.01,
}),
viewportChangePause: 100,
widths: [],
};
const config = {
...defaultConfig.config,
specs: [
// path.join('tests', 'wdio', '**', '*-spec.js'),
path.join('node_modules', 'terra-*', 'packages', '*', 'tests', 'wdio', '**', '*-spec.js'),
],
visualRegression: visualRegressionConfig,
webpackConfig,
bail: 1,
};
// config.spec = [
// // path.join('tests', 'wdio', '**', '*-spec.js'),
// path.join('node_modules', 'terra-*', 'packages', '*', 'tests', 'wdio', '**', '*-spec.js'),
// ];
// config.visualRegression = visualRegressionConfig;
exports.config = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment