-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for mocks #6
Comments
Hi @pkratz |
@FogelAI, I setup a public repo that will hopefully illustrate the mock issue. I also encountered a couple of other issues. They are possibly bugs with the plugin or just my misuse of the plugin and re-exports within my own project. The public repo is a bit of contrived example just to illustrate some of the things I'm seeing. I know some of the re-export stuff of @mui libraries might not make sense in this context, but in my larger project these types of re-exports are legitimate. The repo is located at https://github.com/pkratz/barrel-example The following are the issues I've run into. MocksRun the following to target the test suite with module mocking.
The following are the logs from the run. I am printing out the transformed source code to hopefully better illustrate the problem. The following block from the transformed addToCartWithMock.spec.ts is the relevant block in the test.
This is the relevant block in the transformed addToCart.ts, which is used in the test
So the The tests ultimately error out with the following:
Named exports with Object PatternSome of my packages have named exports that are causing the plugin to update my import to Run the following to target the test suite with this problem.
My '@kratz/security' library has the following export defined in UserContext.tsx which ultimately gets re-exported via a barrel index.
That is the export that is triggering the problem. I think there might need to be a an update to
Type exports causing resetsI've also observed something strange when my barrel file is re-exporting type declaration from other libraries. In this example, I have a "core-ui" package that is acting as a wrapper on top of @mui, so it is explicitly re-exporting types. The barrel file in question is https://github.com/pkratz/barrel-example/blob/main/packages/core-ui/src/index.ts Run the following to target the test suite with this problem.
The following is the transformed source of Welcome.tsx
Typography is being imported by requiring all of coreui from "@kratz/core-ui". I would have expected that this import explicitly target the Typography export from the "@kratz/core-ui" library and be something like:
There is something about the type exports that is triggering the barrel to "resetProperties". fast-json-patch weirdnessIn my larger project we make use of the fast-json-patch npm library. I can ultimately explicitly mock this library to work around the problem I noticed, but I wanted to bring it to your attention in case it's a more systemic issue with the plugin that should be addressed. You can run the following command to trigger this problem.
I see the following relevant failure:
Please let me know if you need any clarification on these examples. Thanks! |
@pkratz Thank you for your detailed explanation. |
@FogelAI, thank you for the quick resolution. v1.0.19 resolves mocks, named exports with object pattern and fast-json-patch! I look forward to your next patch with the type export causing a reset. |
@pkratz |
@FogelAI, that worked beautifully on resolving the type export issue! However, now I'm running into some additional issues. These are unrelated to the new commit, but new issues I was able to encounter when I tried using the latest version of the plugin in my much larger project that has many 3rd party dependencies. I will try to get the two examples of issues that I'm running into into the smaller github repo I set up for barrel import testing, but I figured I'd let you know about them now in the event you get to play around with it before I get a chance to set up a more controlled example. I have a barrel index for a package of ours that is effectively our redux package that is re-exporting redux, redux-undo and some other redux related libraries. The re-export of redux-undo, which we do via, export * from "redux-undo", is causing me issues when using the barrels plugin. When the plugin is processing that export all statement, I run into this error:
In another test case in which I test a component that uses 'react-virtualized' I ran into a different problem. I have the following import in the component being pulled in from the test: import { AutoSizer, List, ListRowProps } from "react-virtualized"; When that statement gets processed, I encounter the following error:
Please let me know if you need me to set this up in a more controlled example, or if this is enough for you to debug further. Thanks! |
@FogelAI, I pushed a commit to https://github.com/pkratz/barrel-example to replicate the redux-undo and react-virtualized originated errors that I'm running into on my larger scale project with the babel-plugin-transform-barrels plugin. You can replicate the errors I'm encountering by running:
The following are the attached logs from the run. This is the relevant error:
The react-virtualized originated error is reproducible by running:
The following are the logs from that run: The relevant error is:
|
@pkratz Thank you again for your detailed explanation. |
This is a tremendous plugin! Thank you for your hard work with this. I was wondering if you had plans on adding support for mocks, such that the mocked modules get replaced with the non-barrel import?
The text was updated successfully, but these errors were encountered: