Last active
February 21, 2018 20:17
-
-
Save CompuIves/3a6195dafc1aa0cc16266528d1991f81 to your computer and use it in GitHub Desktop.
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 puppeteer from 'puppeteer'; | |
const SANDBOXES = [ | |
/* ids */ | |
]; | |
function pageLoaded(page) { | |
return new Promise(async resolve => { | |
// We expose a function which the bundler will call after evaluation | |
await page.exposeFunction('__puppeteer__', () => { | |
if (resolve) { | |
resolve(); | |
} | |
}); | |
}); | |
} | |
describe('sandboxes', () => { | |
let browser = puppeteer.launch({ | |
args: ['--no-sandbox', '--disable-setuid-sandbox'], | |
}); | |
afterAll(() => { | |
browser.close(); | |
}); | |
SANDBOXES.forEach(sandbox => { | |
const id = sandbox.id || sandbox; | |
const threshold = sandbox.threshold || 0.01; | |
it( | |
`loads the sandbox with id '${id}'`, | |
async () => { | |
browser = await browser; | |
const page = await browser.newPage(); | |
const waitFunction = pageLoaded(page); | |
// Go to the page | |
page.goto('http://localhost:3001/#' + id, { | |
timeout: 60000, | |
}); | |
await waitFunction; | |
// Let fetch requests finish before continuing... | |
await page.waitFor(2000); | |
const screenshot = await page.screenshot(); | |
// Check if the snapshot matches | |
expect(screenshot).toMatchImageSnapshot({ | |
customDiffConfig: { | |
threshold, | |
}, | |
customSnapshotIdentifier: id.split('/').join('-'), | |
}); | |
await page.close(); | |
}, | |
1000 * 120 * 1 | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment