-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
babel-preset-viteversion:1.0.4babel-plugin-transform-vite-meta-envversion:1.0.3babel-plugin-transform-vite-meta-globversion:1.0.3@babel/coreversion:7.18.9nodeversion:v14.19.3yarnversion: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:
- 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.globinstead of being relative to the script that usedimport.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 declaredimport.meta.globresides instead of the file that imported, but this isn't important since vite doesn't support this yet.
Metadata
Metadata
Assignees
Labels
No labels