Skip to content

Commit

Permalink
fix: specify "AssertViewOpts" type with all available options
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Sep 30, 2024
1 parent 745258b commit 6a0500d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 91 deletions.
83 changes: 1 addition & 82 deletions src/browser/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,6 @@
import { AssertViewOptsConfig } from "../../config/types";
import { AssertViewOpts } from "../../config/types";
import { ChainablePromiseElement } from "webdriverio";

export interface AssertViewOpts extends Partial<AssertViewOptsConfig> {
/**
* Maximum allowed difference between colors.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#tolerance tolerance} value.
*
* @remarks
* Indicates maximum allowed CIEDE2000 difference between colors. Used only in non-strict mode.
* Increasing global default is not recommended, prefer changing tolerance for particular suites or states instead.
* By default it's 2.3 which should be enough for the most cases.
*
* @defaultValue `2.3`
*/
tolerance?: number;
/**
* Minimum difference in brightness (zero by default) between the darkest/lightest pixel (which is adjacent to the antialiasing pixel) and theirs adjacent pixels.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#antialiasingTolerance antialiasingTolerance} value.
*
* @remarks
* Read more about this option in {@link https://github.com/gemini-testing/looks-same#comparing-images-with-ignoring-antialiasing looks-same}
*
* @defaultValue `4`
*/
antialiasingTolerance?: number;
/**
* Allows testing of regions which bottom bounds are outside of a viewport height.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#compositeImage compositeImage} value.
*
* @remarks
* In the resulting screenshot the area which fits the viewport bounds will be joined with the area which is outside of the viewport height.
*
* @defaultValue `true`
*/
compositeImage?: boolean;
/**
* Allows to specify a delay (in milliseconds) before making any screenshot.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#screenshotDelay screenshotDelay} value.
*
* @remarks
* This is useful when the page has elements which are animated or if you do not want to screen a scrollbar.
*
* @defaultValue `0`
*/
screenshotDelay?: number;
/**
* Ability to set DOM-node selector which should be scroll when the captured element does not completely fit on the screen.
*
* @remarks
* Useful when you capture the modal (popup). In this case a duplicate of the modal appears on the screenshot.
* That happens because we scroll the page using `window` selector, which scroll only the background of the modal, and the modal itself remains in place.
* Default value is `undefined` (it means scroll relative to `window`). Works only when `compositeImage` is `true` (default).
*
* @defaultValue `undefined`
*/
selectorToScroll?: string;
/**
* Ability to disable animations and transitions while making a screenshot
*
* @remarks
* Usefull when you capture screenshot of a page, having animations and transitions.
* Iframe animations are only disabled when using webdriver protocol.
*
* @defaultValue `true`
*/
disableAnimation?: boolean;
/**
* Ability to ignore a small amount of different pixels to classify screenshots as being "identical"
*
* @example 5
* @example '1.5%'
*
* @remarks
* Useful when you encounter a few pixels difference that cannot be eliminated using the tolerance and antialiasingTolerance settings.
*
* @note
* This should be considered a last resort and only used in small number of cases where necessary.
*
* @defaultValue `0`
*/
ignoreDiffPixelCount?: `${number}%` | number;
}

export type AssertViewCommandWithSelector = (
this: WebdriverIO.Browser,
state: string,
Expand Down
88 changes: 83 additions & 5 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export interface BuildDiffOptsConfig {
ignoreCaret: boolean;
}

export interface AssertViewOptsConfig {
export interface AssertViewOpts {
/**
* DOM-node selectors which will be ignored (painted with a black rectangle) when comparing images.
*
* @defaultValue `[]`
*/
ignoreElements: string | Array<string>;
ignoreElements?: string | Array<string>;
/**
* Ability to set capture element from the top area or from current position.
*
Expand All @@ -30,7 +30,7 @@ export interface AssertViewOptsConfig {
*
* @defaultValue `true`
*/
captureElementFromTop: boolean;
captureElementFromTop?: boolean;
/**
* Disables check that element is outside of the viewport left, top, right or bottom bounds.
*
Expand All @@ -42,7 +42,85 @@ export interface AssertViewOptsConfig {
*
* @defaultValue `false`
*/
allowViewportOverflow: boolean;
allowViewportOverflow?: boolean;
/**
* Maximum allowed difference between colors.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#tolerance tolerance} value.
*
* @remarks
* Indicates maximum allowed CIEDE2000 difference between colors. Used only in non-strict mode.
* Increasing global default is not recommended, prefer changing tolerance for particular suites or states instead.
* By default it's 2.3 which should be enough for the most cases.
*
* @defaultValue `2.3`
*/
tolerance?: number;
/**
* Minimum difference in brightness (zero by default) between the darkest/lightest pixel (which is adjacent to the antialiasing pixel) and theirs adjacent pixels.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#antialiasingTolerance antialiasingTolerance} value.
*
* @remarks
* Read more about this option in {@link https://github.com/gemini-testing/looks-same#comparing-images-with-ignoring-antialiasing looks-same}
*
* @defaultValue `4`
*/
antialiasingTolerance?: number;
/**
* Allows testing of regions which bottom bounds are outside of a viewport height.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#compositeImage compositeImage} value.
*
* @remarks
* In the resulting screenshot the area which fits the viewport bounds will be joined with the area which is outside of the viewport height.
*
* @defaultValue `true`
*/
compositeImage?: boolean;
/**
* Allows to specify a delay (in milliseconds) before making any screenshot.
* Overrides config {@link https://github.com/gemini-testing/testplane#browsers browsers}.{@link https://github.com/gemini-testing/testplane#screenshotDelay screenshotDelay} value.
*
* @remarks
* This is useful when the page has elements which are animated or if you do not want to screen a scrollbar.
*
* @defaultValue `0`
*/
screenshotDelay?: number;
/**
* Ability to set DOM-node selector which should be scroll when the captured element does not completely fit on the screen.
*
* @remarks
* Useful when you capture the modal (popup). In this case a duplicate of the modal appears on the screenshot.
* That happens because we scroll the page using `window` selector, which scroll only the background of the modal, and the modal itself remains in place.
* Default value is `undefined` (it means scroll relative to `window`). Works only when `compositeImage` is `true` (default).
*
* @defaultValue `undefined`
*/
selectorToScroll?: string;
/**
* Ability to disable animations and transitions while making a screenshot
*
* @remarks
* Usefull when you capture screenshot of a page, having animations and transitions.
* Iframe animations are only disabled when using webdriver protocol.
*
* @defaultValue `true`
*/
disableAnimation?: boolean;
/**
* Ability to ignore a small amount of different pixels to classify screenshots as being "identical"
*
* @example 5
* @example '1.5%'
*
* @remarks
* Useful when you encounter a few pixels difference that cannot be eliminated using the tolerance and antialiasingTolerance settings.
*
* @note
* This should be considered a last resort and only used in small number of cases where necessary.
*
* @defaultValue `0`
*/
ignoreDiffPixelCount?: `${number}%` | number;
}

export interface ExpectOptsConfig {
Expand Down Expand Up @@ -133,7 +211,7 @@ export interface CommonConfig {
antialiasingTolerance: number;
compareOpts: CompareOptsConfig;
buildDiffOpts: BuildDiffOptsConfig;
assertViewOpts: AssertViewOptsConfig;
assertViewOpts: AssertViewOpts;
expectOpts: ExpectOptsConfig;
meta: { [name: string]: unknown };
windowSize: string | { width: number; height: number } | null;
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ export type {
Test,
Suite,
TestError,
AssertViewOpts,
HermioneCtx,
GlobalHelper,
TestplaneCtx,
TestFunctionCtx,
} from "./types";
export type { Config } from "./config";
export type { ConfigInput } from "./config/types";
export type { ConfigInput, AssertViewOpts } from "./config/types";
export type {
TestCollection,
FormatterTreeSuite,
Expand Down
2 changes: 0 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export type { Test } from "../test-reader/test-object/test";
export type { Suite } from "../test-reader/test-object/suite";
export type { TestFunctionCtx } from "../test-reader/test-object/types";

export type { AssertViewOpts } from "../browser/commands/types";

export interface RootSuite extends Suite {
root: true;
}
Expand Down

0 comments on commit 6a0500d

Please sign in to comment.