Skip to content

Instantly share code, notes, and snippets.

@AshCoolman
Created January 19, 2018 12:11
Show Gist options
  • Save AshCoolman/b5b9e86975f4371fa4b35beef4f0e428 to your computer and use it in GitHub Desktop.
Save AshCoolman/b5b9e86975f4371fa4b35beef4f0e428 to your computer and use it in GitHub Desktop.
Differencify live vs test
import Differencify from '../index';
const differencify = new Differencify({ debug: true });
describe('Differencify', async () => {
let target;
let page;
beforeAll(async () => {
await differencify.launchBrowser({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: false });
target = differencify.init({ chain: false });
page = await target.newPage();
await page.setViewport({ width: 1024, height: 1024 });
});
afterAll(async () => {
await page.close();
await differencify.cleanup();
});
const ENVS = {
test: {
name: 'TEST',
domain: 'https://test.example.com',
},
live: {
name: 'LIVE',
domain: 'https://www.example.com',
compare: ['TEST'],
},
};
const SNAPSHOT_DETAILS = [{
name: 'Home',
url: '/',
selector: null,
envs: [ENVS.test, ENVS.live],
}];
describe('VisDiff:', async () => {
const cache = {};
SNAPSHOT_DETAILS.forEach(({ url, name, envs }) => {
envs.forEach(async (env) => {
const TEST = `${env.name}:${name}`;
it(TEST, async () => {
await page.goto(`${env.domain}${url}`);
cache[TEST] = await page.screenshot();
const result = await target.toMatchSnapshot(cache[TEST]);
expect(result).toEqual(true);
}, 20000);
if (env.compare) {
env.compare.forEach(async (compEnvName) => {
it(`${env.name} vs ${compEnvName}`, async () => {
const compImage = cache[`${compEnvName}:${name}`];
expect(compImage).toBeDefined();
expect(
await target.toMatchSnapshot(compImage),
).toEqual(true);
}, 20000);
});
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment