@rws-air/jestscreenshot
Version:
Jest reporter plugin to take Puppeteer screenshots on failing tests
159 lines • 5.06 kB
TypeScript
/// <reference types="node" />
import { Page } from 'puppeteer';
export declare class JestScreenshotError extends Error {
/**
* Constructs a new JestScreenshotError
* @param message Message to append to standard message for JestScreenshotError
*/
constructor(message: string);
}
export interface JestScreenshotOptions {
/** The Puppeteer page to take a screenshot from */
page: Page;
/** The directory to create a "screenshots" folder in */
dirName: string;
/**
* @description An optional name of the script that is currently being ran
* @default jest-test
*/
testName?: string;
/**
* Optionally upload screenshots to slack after making them
* Requires you pass a token to the slackToken option, or set the SLACK_WEBTOKEN environment variable
* @default false
*/
slackUpload?: boolean;
/**
* Token to use when uploading to Slack
* Only used when slackUpload is set to true
* Recommended to pass this as SLACK_WEBTOKEN environment variable instead!
* @default ''
*/
slackToken?: string;
/**
* Channels to send the Slack upload to
* Should be an array of Slack channel IDs
* Only used when slackUpload is set to true
* @example
* ```typescript
* {
* slackChannels: ['C1234567890', 'C2345678901', 'C3456789012']
* }
* ```
*/
slackChannels?: string[];
}
/** Represents all data returned by Slack when uploading a file */
export interface SlackFile {
id: string;
created: number;
timestamp: number;
name: string;
title: string;
mimetype: string;
filetype: string;
pretty_type: string;
user: string;
editable: boolean;
size: number;
mode: string;
is_external: boolean;
external_type: string;
is_public: boolean;
public_url_shared: boolean;
display_as_bot: boolean;
username: string;
url_private: string;
url_private_download: string;
thumb_64: string;
thumb_80: string;
thumb_360: string;
thumb_360_w: number;
thumb_360_h: number;
thumb_480: string;
thumb_480_w: number;
thumb_480_h: number;
thumb_160: string;
image_exif_rotation: number;
original_w: number;
original_h: number;
permalink: string;
permalink_public: string;
comments_count: number;
is_starred: boolean;
shares: {
private: {
[key: string]: {
reply_users: string[];
reply_users_count: number;
reply_count: number;
ts: string;
};
};
};
channels: string[];
groups: string[];
ims: string[];
has_rich_preview: boolean;
}
/** Represents the response by Slack when uploading a file */
export interface SlackResponse {
ok: boolean;
file: SlackFile;
}
/**
* The main class of JestScreenshot that should be initialized with config
*
* @remarks Jest reporter plugin to take Puppeteer screenshots on failing tests
*
* @param page The Puppeteer page object to screenshot
* @param dirName The directory to create a "screenshots" folder in
* @param testName An optional name of the script that is currently being ran
* @param slackUpload Optionally upload screenshots to slack after making them.
*
* Requires you pass a token to the slackToken option, or set the SLACK_WEBTOKEN environment variable
* @param slackToken Token to use when uploading to slack. Required when you pass slackUpload=true
*
* Optionally you can also pass this through the environment variable "SLACK_WEBTOKEN".
*
* This environment variable will take priority over passing it as option
*
* @param slackChannels Channels to send the Slack upload to
*
* Should be an array of Slack channel IDs
*
* Only used when slackUpload is set to true
*/
export declare class JestScreenshot {
private page;
private dirName;
private testName;
private shouldUploadToSlack;
private slackToken;
private slackChannels;
/**
* Constructs a new JestScreenshot
* @param options The options to pass to the instance of JestScreenshot
*/
constructor(options: JestScreenshotOptions);
/**
* Sets up the JestScreenshot reporter
*
* @returns JestScreenshot reporter will have been initialiazed as a side effect for this test suite
*/
setup(): Promise<void>;
/**
* Takes a screenshot of the current page
* @returns Either returns the response from Slack or the screenshot as a Buffer
*/
takeScreenshot(): Promise<SlackResponse | Buffer>;
/**
* Uploads screenshots to Slack using the provided token
*
* @param screenshot base64 representation of the screenshot to upload
* @returns {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise | Promise} of the SlackResponse
*/
uploadToSlack(screenshot: Buffer, fileName: string): Promise<SlackResponse>;
}
export default JestScreenshot;
//# sourceMappingURL=index.d.ts.map