vitest-dev / vitest-dev/vitest

BrowserMode: browser.expect.toMatchScreenshot.beforeComparsion hook

Open
#9,341 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement: pending triage
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Clear and concise description of the problem

Sometimes you need to make some transformations with images in screenshot tests before comparison.

Now you have only one way - write custom comparator func, but it is difficult way

Suggested solution

allow describe the hook, what called always before image comparator runs

export default defineConfig({
  test: {
    browser: {
      expect: {
        toMatchScreenshot: {
          beforeComparsion: async (pathToReference: string, pathToActual: string): Promise<void> => {...},
          comparators: {
            ...
          },
        },
      },
    },
  },
})
Alternative

No response

Additional context

No response

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the browser expect.toMatchScreenshot implementation and its comparator configuration entry point described in the issue. Trace how reference and actual image paths reach the comparator, then verify that the proposed beforeComparsion hook runs before comparison and that existing comparator behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.