Created
March 24, 2021 16:51
-
-
Save csouchet/0f070cb42258dfd756cbea5e10cdf735 to your computer and use it in GitHub Desktop.
Reuse the snapshots with Jest-image-snapshot 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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