var config = require('./diff-config.json') dir = 'http://localhost:1313', waitToScreenShotTime = 500, additionalPages = ['404.html'], console.log('Config being used', { const fetch = require(/^http:/.test(dir) ? 'http' : 'https') const Differencify = require('differencify') const differencify = new Differencify() // WARNING: Chnaging these values may invalidate previous snapshots const viewports = Object.freeze({ phone: Object.freeze({ width: 320, height: 1000 }), tablet: Object.freeze({ width: 768, height: 4000 }), massive: Object.freeze({ width: 1440, height: 4000 }), const viewportKeys = Object.keys(viewports) const pages = (await fetch_json(`${dir}/index.json`)) .concat(additionalPages.map(p => `${dir}/${p}`)) console.log(`Diffing these pages:`) // Populates stack with tests for (const pagePath of pages) { console.log('\t' + pagePath.trim().replace(dir, '')) for (const viewportName of viewportKeys) { stack.push(() => checkPage(pagePath, viewportName)) await differencify.launchBrowser({ timeout: 0 }) await differencify.cleanup() if (nonIdentical.length) { console.log(`Pages that have changed:`) console.log('No differences detected') * @param {string} url path to page * @param {string} viewportName key to viewport config async function checkPage(url, viewportName) { const viewport = viewports[viewportName] const path = url.replace(dir, '') const testName = `page-${viewportName}-${safeFileName(path)}` .init({ testName, timeout: 0 }) .wait(waitToScreenShotTime) if (!result) nonIdentical.push(`${viewportName} ${path}`) if (verbose) console.log(`checked ${viewportName} ${path}`) * Fetches and parses JSON from web resource * @param {string} url to resource to fetch function fetch_json(url) { return new Promise(resolve => res.on('data', data => (body += data)) res.on('end', () => resolve(JSON.parse(body))) * Creates a file safe string * @param {string} str Possibly unsafe url function safeFileName(str) { .replace(/[^a-z0-9]/gi, '_') * @param {Function[]} stack The fucntions to be called function concurrence(stack) { const er = e => console.error(e) return new Promise(resolve => { while (count < maxJobs) { if (count === 0 && stack.length === 0) return resolve()