Skip to content

Instantly share code, notes, and snippets.

@csouchet
Created March 24, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csouchet/0f070cb42258dfd756cbea5e10cdf735 to your computer and use it in GitHub Desktop.
Save csouchet/0f070cb42258dfd756cbea5e10cdf735 to your computer and use it in GitHub Desktop.
Reuse the snapshots with Jest-image-snapshot 2
import { getConfig } from './helpers/visu-utils';
function async gotoPageWithBPMNContainer(margin: number): Promise<ElementHandle<Element>> {
// Redirect the current page in the browser to a new url with puppeteer
const response = await page.goto(‘http://localhost:10002/rendering-diagram.html?bpmn=./gateways.bpmn&fitMargin=${margin}’);
// Be sure the page is displayed correctly with puppeteer & Jest
expect(response.status()).toBe(200);
await expect(page.title()).resolves.toMatch('BPMN Visualization - Diagram Rendering' );
return await page.waitForSelector(‘#bpmn-container’, { timeout: 5_000 });
}
it.each([-100, 0, null])('load with margin %s', async (margin: number) => {
const bpmnContainerElement = await gotoPageWithBPMNContainer(margin);
// Take the screenshot of the page with puppeteer
const image = await page.screenshot({ fullPage: true });
// Compare the taken screenshot with the baseline screenshot (if exists), or create it (else)
const config = getConfig(‘load_with_no_margin’,`__image_snapshots__/__diff_output__/${margin}`);
expect(image).toMatchImageSnapshot(config);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment