Transforming image in Vitest in Next.js codebase

Jest has a way to (not) process imported assets (.jpg, .png, …) by setting what should be the resolved value. So it can be a mock object:

jest.config.js

module.exports = {
  transform: {
    '\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/fileTransformer.js',
  },
};

As for Vite, I can’t find an equivalent option to do that. The reason I need to do it is that in our Next.js codebase, we have some dynamic require('../path/to/image')s in our pages which Next.js resolves to an object which contains, among other things, src property. But Vitest by default resolves such require by returning the content of the image, which in the test results into SyntaxError: Invalid or unexpected token (on the line of the require).

So is there a way to make Vite transform assets in particular way so that it conforms to Next’s image resolution mechanism?