You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jest has a way to (not) process imported assets (.jpg, .png, ...) by setting what should be the resolved value. So it can resolve imported assets to eg. a mock object:
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, width and other properties. But Vitest by default resolves such require differently, 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?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Jest has a way to (not) process imported assets (.jpg, .png, ...) by setting what should be the resolved value. So it can resolve imported assets to eg. a mock object:
jest.config.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
,width
and other properties. But Vitest by default resolves such require differently, which in the test results intoSyntaxError: Invalid or unexpected token
(on the line of therequire
).So is there a way to make Vite transform assets in particular way so that it conforms to Next's image resolution mechanism?
Beta Was this translation helpful? Give feedback.
All reactions