Skip to content

Commit b17e38d

Browse files
committed
refactor(browser): get annotate from matcher state in toMatchScreenshot
1 parent 5aa84d5 commit b17e38d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/browser/src/client/tester/expect/toMatchScreenshot.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AsyncExpectationResult, MatcherState } from '@vitest/expect'
22
import type { ScreenshotMatcherOptions } from '../../../../context'
33
import type { ScreenshotMatcherArguments, ScreenshotMatcherOutput } from '../../../shared/screenshotMatcher/types'
44
import type { Locator } from '../locators'
5-
import { getBrowserState, getWorkerState } from '../../utils'
5+
import { getBrowserState } from '../../utils'
66
import { convertToSelector } from '../tester-utils'
77

88
const counters = new Map<string, { current: number }>([])
@@ -19,13 +19,11 @@ export default async function toMatchScreenshot(
1919
throw new Error('\'toMatchScreenshot\' cannot be used with "not"')
2020
}
2121

22-
const currentTest = getWorkerState().current
23-
24-
if (currentTest === undefined || this.currentTestName === undefined) {
22+
if (this.task === undefined || this.currentTestName === undefined) {
2523
throw new Error('\'toMatchScreenshot\' cannot be used without test context')
2624
}
2725

28-
const counterName = `${currentTest.result?.repeatCount ?? 0}${this.testPath}${this.currentTestName}`
26+
const counterName = `${this.task.result?.repeatCount ?? 0}${this.testPath}${this.currentTestName}`
2927
let counter = counters.get(counterName)
3028

3129
if (counter === undefined) {
@@ -66,8 +64,8 @@ export default async function toMatchScreenshot(
6664
] satisfies ScreenshotMatcherArguments,
6765
)
6866

69-
if (result.pass === false && 'context' in currentTest) {
70-
const { annotate } = currentTest.context
67+
if (result.pass === false) {
68+
const { annotate } = this.task.context
7169

7270
const annotations: ReturnType<typeof annotate>[] = []
7371

0 commit comments

Comments
 (0)