Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/tasty-forks-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@wdio/visual-service": patch
---

# 🐛 Bugfixes

## #1084 expect(...).toMatch*Snapshot methods do not have Promise return types

The methods should be typed as promises

# Committers: 1

- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))
34 changes: 21 additions & 13 deletions packages/visual-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ declare global {
*/
toMatchScreenSnapshot(
tag: string,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
options?: WdioCheckScreenMethodOptions
): R
): Promise<R>
toMatchScreenSnapshot(
tag: string,
options?: WdioCheckScreenMethodOptions
): R
): Promise<R>
/**
* Checks that if the full page screenshot matches with snapshot of baseline.
* @param tag snapshot name
Expand All @@ -127,13 +127,13 @@ declare global {
*/
toMatchFullPageSnapshot(
tag: string,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
options?: WdioCheckFullPageMethodOptions
): R
): Promise<R>
toMatchFullPageSnapshot(
tag: string,
options?: WdioCheckFullPageMethodOptions
): R
): Promise<R>
/**
* Checks that if given element matches with snapshot of baseline.
* @param tag snapshot name
Expand All @@ -142,13 +142,13 @@ declare global {
*/
toMatchElementSnapshot(
tag: string,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
options?: WdioCheckElementMethodOptions
): R
): Promise<R>
toMatchElementSnapshot(
tag: string,
options?: WdioCheckElementMethodOptions
): R
): Promise<R>
/**
* Checks that if the full page screenshot including tab marks matches with snapshot of baseline.
* @param tag snapshot name
Expand All @@ -157,17 +157,25 @@ declare global {
*/
toMatchTabbablePageSnapshot(
tag: string,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
options?: WdioCheckFullPageMethodOptions
): R
): Promise<R>
toMatchTabbablePageSnapshot(
tag: string,
options?: WdioCheckFullPageMethodOptions
): R
): Promise<R>
}
}
}
export type { VisualServiceOptions }
export type {
VisualServiceOptions,
WdioCheckElementMethodOptions,
WdioCheckScreenMethodOptions,
WdioCheckFullPageMethodOptions,
WdioSaveElementMethodOptions,
WdioSaveScreenMethodOptions,
WdioSaveFullPageMethodOptions
}

export default WdioImageComparisonService
export const launcher = VisualLauncher
16 changes: 8 additions & 8 deletions packages/visual-service/src/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const asymmetricMatcher =
? Symbol.for('jest.asymmetricMatcher')
: 0x13_57_a5

function isAsymmetricMatcher (expected: unknown): expected is ExpectWebdriverIO.PartialMatcher {
function isAsymmetricMatcher (expected: unknown): expected is ExpectWebdriverIO.PartialMatcher<number> {
return Boolean(expected && typeof expected === 'object' && '$$typeof' in expected && expected.$$typeof === asymmetricMatcher && 'asymmetricMatch' in expected)
}
function evaluateResult(
result: ImageCompareResult,
expected: number | ExpectWebdriverIO.PartialMatcher,
expected: number | ExpectWebdriverIO.PartialMatcher<number>,
instanceName: string
) {
if (isAsymmetricMatcher(expected)) {
Expand Down Expand Up @@ -58,7 +58,7 @@ function isMultiremoteResult(
return typeof result === 'object' && Object.values(result)[0]?.misMatchPercentage !== undefined
}

function compareResult (result: ImageCompareResult, expected: number | ExpectWebdriverIO.PartialMatcher) {
function compareResult (result: ImageCompareResult, expected: number | ExpectWebdriverIO.PartialMatcher<number>) {
const isMultiremote = isMultiremoteResult(result)
const results = isMultiremote
? Object.entries(result as unknown as Record<string, ImageCompareResult>).map(([instanceName, instanceResult]) => ({
Expand Down Expand Up @@ -86,7 +86,7 @@ function compareResult (result: ImageCompareResult, expected: number | ExpectWeb

function parseMatcherParams (
tag: string,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
options?: WdioCheckFullPageMethodOptions
) {
/**
Expand Down Expand Up @@ -125,7 +125,7 @@ function parseMatcherParams (
export async function toMatchScreenSnapshot (
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
tag: string,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
optionsOrUndefined?: WdioCheckScreenMethodOptions
) {
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
Expand All @@ -136,7 +136,7 @@ export async function toMatchScreenSnapshot (
export async function toMatchFullPageSnapshot (
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
tag: string,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
optionsOrUndefined?: WdioCheckFullPageMethodOptions
) {
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
Expand All @@ -147,7 +147,7 @@ export async function toMatchFullPageSnapshot (
export async function toMatchElementSnapshot (
element: WebdriverIO.Element,
tag: string,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
optionsOrUndefined?: WdioCheckElementMethodOptions
) {
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
Expand All @@ -159,7 +159,7 @@ export async function toMatchElementSnapshot (
export async function toMatchTabbablePageSnapshot (
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
tag: string,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
optionsOrUndefined?: WdioCheckFullPageMethodOptions
) {
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
Expand Down
Loading