@@ -2,7 +2,7 @@ import type { AsyncExpectationResult, MatcherState } from '@vitest/expect'
22import type { ScreenshotMatcherOptions } from '../../../../context'
33import type { ScreenshotMatcherArguments , ScreenshotMatcherOutput } from '../../../shared/screenshotMatcher/types'
44import type { Locator } from '../locators'
5- import { getBrowserState , getWorkerState } from '../../utils'
5+ import { getBrowserState } from '../../utils'
66import { convertToSelector } from '../tester-utils'
77
88const 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