Package Exports
- @jeeyah/jestscreenshot
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jeeyah/jestscreenshot) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jestscreenshot
Extend Jest and Puppeteer to automatically take screenshots after each test failure or success.
Screen shots will be created in a subdirectory of your test script as follows.
Success: screenshots/scriptname-testname.png Failure: screenshots/0-fail-scriptname-testname.png
Import jestscreenshot
let jestscreenshot = require('@jeeyah/jestscreenshot');In beforeAll, initialize jestscreenshot after initializing Puppeteer
beforeAll(async () => {
// Create puppeteer browser and page objects first:
//
// browser = await options.puppeteer.launch
// page = await ret.browser.newPage();
let path = require('path');
let scriptName = path.basename(__filename).replace('.js', '');
/** page: page object returned from Puppeteer
* dirName: __dirname defaults to same directory as script
* scriptName: Used in the screen shot file name
*/
let options = {
page: page,
dirName: __dirname,
scriptName: scriptName
};
await jestscreenshot.init(options);In afterAll, configure jestscreenshot cleanup just prior to closing browser
jestscreenshot needs to wait for screen shots to finish before the browser closes.
exports.afterAll = async function(browser) {
jestscreenshot.cleanup(function () {
if (browser) {
browser.close();
}
exports.close();
});
};