regressify
Version:
Visual regression tests support
48 lines • 1.61 kB
JavaScript
import chalk from 'chalk';
import backstop from 'backstopjs';
import { getLibraryPath } from './helpers.js';
import path from 'path';
import fs from 'fs';
import { getConfig } from './config.js';
const PATCH_START = '<!-- PATCH START -->';
const PATCH_END = '<!-- PATCH END -->';
const customStyle = `
${PATCH_START}
<style>
[id^="test"] > div[display="true"] > p[display] {
white-space: pre;
overflow-x: auto;
}
</style>
${PATCH_END}
`;
export async function regressifyProcess(command, args) {
packCompare();
const config = getConfig(args);
backstop(command, { config })
.then(() => {
console.log(chalk.green(command.toUpperCase() + ' FINISHED SUCCESSFULLY'));
})
.catch(() => {
console.log(chalk.red(command.toUpperCase() + ' FAILED'));
});
}
function packCompare() {
const reportIndex = path.resolve(getLibraryPath(), 'node_modules/backstopjs/compare/output/index.html');
if (fs.existsSync(reportIndex)) {
let html = fs.readFileSync(reportIndex, 'utf-8');
const patchStartIndex = html.indexOf(PATCH_START);
const patchEndIndex = html.indexOf(PATCH_END);
if (patchStartIndex > 0 && patchEndIndex > patchStartIndex) {
html = html.replace(new RegExp(PATCH_START + '.*' + patchEndIndex, 'gi'), customStyle);
}
else {
html = html.replace('</head>', customStyle + '</head>');
}
fs.writeFileSync(reportIndex, html);
}
else {
console.log(chalk.red('File does not exist: ' + reportIndex));
}
}
//# sourceMappingURL=regressify.js.map