From 6a0500d2361672ae49a3ea1c64d25cd6ec2e78e4 Mon Sep 17 00:00:00 2001 From: DudaGod Date: Fri, 27 Sep 2024 16:07:13 +0300 Subject: [PATCH] fix: specify "AssertViewOpts" type with all available options --- src/browser/commands/types.ts | 83 +-------------------------------- src/config/types.ts | 88 +++++++++++++++++++++++++++++++++-- src/index.ts | 3 +- src/types/index.ts | 2 - 4 files changed, 85 insertions(+), 91 deletions(-) diff --git a/src/browser/commands/types.ts b/src/browser/commands/types.ts index 7396231b9..937cb2cc2 100644 --- a/src/browser/commands/types.ts +++ b/src/browser/commands/types.ts @@ -1,87 +1,6 @@ -import { AssertViewOptsConfig } from "../../config/types"; +import { AssertViewOpts } from "../../config/types"; import { ChainablePromiseElement } from "webdriverio"; -export interface AssertViewOpts extends Partial { - /** - * 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, diff --git a/src/config/types.ts b/src/config/types.ts index 62d4769c2..f3a265968 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -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; + ignoreElements?: string | Array; /** * Ability to set capture element from the top area or from current position. * @@ -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. * @@ -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 { @@ -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; diff --git a/src/index.ts b/src/index.ts index c2346ed05..f77383c80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, diff --git a/src/types/index.ts b/src/types/index.ts index 5e562d26a..63b0e4bf4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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; }