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
I was trying to unit test my vite, react, typescript project which has a working file based routing, done by leveraging the import.meta.glob feature.
I used this library to replace the occurrence of import.meta.glob, but it is not behaving like vite's implementation since it is not supported outside the vite environment, jest in this case.
What happened:
While the code is working well with vite (dev server and production build), under tests it is always returning an empty object
unless the glob pattern is changed to be relative to the test file that will import it.
It seems like the glob implementation of this library doesn't take the root project path as the root of the glob search
The search is done relative to the root script/the script that used the import.meta.glob instead of being relative to the script that used import.meta.glob.
Suggested solution:
if the glob pattern starts with / the glob pattern must be applied to the project directory instead of the root of the file system.
if the glob pattern starts with . the pattern must be applied to the folder where the file that declared import.meta.glob resides instead of the file that imported, but this isn't important since vite doesn't support this yet.
The text was updated successfully, but these errors were encountered:
babel-preset-vite
version:1.0.4
babel-plugin-transform-vite-meta-env
version:1.0.3
babel-plugin-transform-vite-meta-glob
version:1.0.3
@babel/core
version:7.18.9
node
version:v14.19.3
yarn
version:1.22.19
Relevant code or config:
Reproducible repo: https://codesandbox.io/s/beautiful-roman-sjjvdg?file=/test/Posts.spec.tsx
What you did:
I was trying to unit test my vite, react, typescript project which has a working file based routing, done by leveraging the
import.meta.glob
feature.I used this library to replace the occurrence of
import.meta.glob
, but it is not behaving like vite's implementation since it is not supported outside the vite environment, jest in this case.What happened:
While the code is working well with vite (dev server and production build), under tests it is always returning an empty object
unless the glob pattern is changed to be relative to the test file that will import it.
Reproduction:
Reproducible repo: https://codesandbox.io/s/beautiful-roman-sjjvdg?file=/test/Posts.spec.tsx
Problem description:
import.meta.glob
instead of being relative to the script that usedimport.meta.glob
.Suggested solution:
/
the glob pattern must be applied to the project directory instead of the root of the file system..
the pattern must be applied to the folder where the file that declaredimport.meta.glob
resides instead of the file that imported, but this isn't important since vite doesn't support this yet.The text was updated successfully, but these errors were encountered: