@error-paparazzi/jest
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -5,4 +5,5 @@ import { LaunchOptions } from "puppeteer"; | ||
} | ||
export declare const screenshot: ({ launchOptions }?: IScreenshotOptions) => Promise<void>; | ||
export declare const takeScreenshot: ({ launchOptions }?: IScreenshotOptions) => Promise<void>; | ||
export declare const paparazzi: (fn: any, options?: IScreenshotOptions) => () => Promise<void>; | ||
export declare const takeScreenshotOnTestError: (options?: IScreenshotOptions) => void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const puppeteer_1 = __importDefault(require("puppeteer")); | ||
exports.screenshot = async ({ launchOptions } = { launchOptions: {} }) => { | ||
exports.takeScreenshot = async ({ launchOptions } = { launchOptions: {} }) => { | ||
const browser = await puppeteer_1.default.launch(launchOptions); | ||
@@ -19,15 +19,15 @@ const page = await browser.newPage(); | ||
}; | ||
exports.paparazzi = (fn, options = { launchOptions: {} }) => async () => { | ||
try { | ||
await fn(); | ||
} | ||
catch (e) { | ||
if (!is_ci_1.default) | ||
await exports.takeScreenshot(options); | ||
throw e; | ||
} | ||
}; | ||
exports.takeScreenshotOnTestError = (options = { launchOptions: {} }) => { | ||
const wrapTestToMakeScreenshotOnError = (fn) => async () => { | ||
try { | ||
await fn(); | ||
} | ||
catch (e) { | ||
if (!is_ci_1.default) | ||
await exports.screenshot(options); | ||
throw e; | ||
} | ||
}; | ||
const wrapApply = (target, that, args) => { | ||
args[1] = wrapTestToMakeScreenshotOnError(args[1]); | ||
args[1] = exports.paparazzi(args[1], options); | ||
target.apply(that, args); | ||
@@ -34,0 +34,0 @@ }; |
{ | ||
"name": "@error-paparazzi/jest", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Make screenshot of JSDOM when your jest test failed", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,3 +10,3 @@ import isCi from "is-ci"; | ||
export const screenshot = async ( | ||
export const takeScreenshot = async ( | ||
{ launchOptions }: IScreenshotOptions = { launchOptions: {} } | ||
@@ -22,16 +22,19 @@ ) => { | ||
export const paparazzi = ( | ||
fn: any, | ||
options: IScreenshotOptions = { launchOptions: {} } | ||
) => async () => { | ||
try { | ||
await fn(); | ||
} catch (e) { | ||
if (!isCi) await takeScreenshot(options); | ||
throw e; | ||
} | ||
}; | ||
export const takeScreenshotOnTestError = ( | ||
options: IScreenshotOptions = { launchOptions: {} } | ||
) => { | ||
const wrapTestToMakeScreenshotOnError = (fn: any) => async () => { | ||
try { | ||
await fn(); | ||
} catch (e) { | ||
if (!isCi) await screenshot(options); | ||
throw e; | ||
} | ||
}; | ||
const wrapApply = (target: jest.It, that: any, args: Parameters<jest.It>) => { | ||
args[1] = wrapTestToMakeScreenshotOnError(args[1]); | ||
args[1] = paparazzi(args[1], options); | ||
target.apply(that, args); | ||
@@ -38,0 +41,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11913
147