Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from TodayTix/feature/set-customimage-snapshot-…
Browse files Browse the repository at this point in the history
…options

Feature/set customimage snapshot options
  • Loading branch information
aashihmin authored Sep 10, 2020
2 parents ea0e3ec + a0f1a37 commit 0e53f7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dist/lib/react/ReactScreenshotTest.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="react" />
import { MatchImageSnapshotOptions } from "jest-image-snapshot";
import { Viewport } from "../screenshot-renderer/api";
import { Page } from "puppeteer";
/**
Expand All @@ -22,11 +23,16 @@ export declare class ReactScreenshotTest {
private readonly _staticPaths;
private readonly _onPageLoadedCallbacks;
private ran;
private customImageSnapshotOptions;
/**
* Creates a screenshot test.
*/
static create(componentName: string): ReactScreenshotTest;
private constructor();
/**
* Set custom options for image snapshot testing.
*/
setCustomImageSnapshotOptions(options: MatchImageSnapshotOptions): this;
/**
* Adds a set of viewports to the screenshot test.
*/
Expand Down
9 changes: 9 additions & 0 deletions dist/lib/react/ReactScreenshotTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ReactScreenshotTest {
this._staticPaths = {};
this._onPageLoadedCallbacks = {};
this.ran = false;
this.customImageSnapshotOptions = {};
setImmediate(() => {
if (!this.ran) {
throw new Error("Please call .run()");
Expand All @@ -48,6 +49,13 @@ class ReactScreenshotTest {
static create(componentName) {
return new this(componentName);
}
/**
* Set custom options for image snapshot testing.
*/
setCustomImageSnapshotOptions(options) {
this.customImageSnapshotOptions = { ...options };
return this;
}
/**
* Adds a set of viewports to the screenshot test.
*/
Expand Down Expand Up @@ -168,6 +176,7 @@ class ReactScreenshotTest {
failureThresholdType: 'percent',
customSnapshotsDir: path_1.join(snapshotsDir, "__screenshots__", this.componentName, subdirectory),
customSnapshotIdentifier: `${filenamePrefix}${viewportName} - ${shotName}`,
...this.customImageSnapshotOptions,
});
logDebug(`Screenshot compared.`);
}
Expand Down
13 changes: 12 additions & 1 deletion src/lib/react/ReactScreenshotTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import callsites from "callsites";
import chalk from "chalk";
import { existsSync } from "fs";
import { toMatchImageSnapshot } from "jest-image-snapshot";
import { MatchImageSnapshotOptions, toMatchImageSnapshot } from "jest-image-snapshot";
import { dirname, join, sep } from "path";
import { debugLogger } from "../logger";
import { fetch } from "../network/fetch";
Expand Down Expand Up @@ -49,6 +49,8 @@ export class ReactScreenshotTest {

private ran = false;

private customImageSnapshotOptions: MatchImageSnapshotOptions = {};

/**
* Creates a screenshot test.
*/
Expand All @@ -64,6 +66,14 @@ export class ReactScreenshotTest {
});
}

/**
* Set custom options for image snapshot testing.
*/
setCustomImageSnapshotOptions(options: MatchImageSnapshotOptions) {
this.customImageSnapshotOptions = { ...options };
return this;
}

/**
* Adds a set of viewports to the screenshot test.
*/
Expand Down Expand Up @@ -212,6 +222,7 @@ export class ReactScreenshotTest {
subdirectory
),
customSnapshotIdentifier: `${filenamePrefix}${viewportName} - ${shotName}`,
...this.customImageSnapshotOptions,
});
logDebug(`Screenshot compared.`);
} else {
Expand Down

0 comments on commit 0e53f7f

Please sign in to comment.