-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(devkit): expose TempFs via @nx/devkit/testing #30229
base: master
Are you sure you want to change the base?
Conversation
View your CI Pipeline Execution ↗ for commit 0ee88b5.
☁️ Nx Cloud last updated this comment at |
754036d
to
0ee88b5
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs look good
|
||
Generators will be created with a default test suite. You can add additional tests to this test suite to ensure that your generator is working as expected. | ||
|
||
If your generator makes use of or composes generators that make use of Inferred Tasks or Inference Plugins, you will need additional setup in your test suite to ensure that any plugins registered in your current Nx Workspace do not interfere with the unit tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this. 😕
This is indeed the case.. but how are developers supposed to know that generators they're importing are using inferences plugins or not?
Can we explore creating a TempFs
when we create a tree? 👀 Which is already public testing API.. and used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t currently require tear down logic for when unit testing with create tree, because it’s all in-memory.
To change that API to start creating TempFs would mean countless unit tests in countless projects would start creating real temp dirs on real machines, that would not be cleaned up.
As for discoverability of whether the generator uses inference or not, that’s a separate issue.
But they should at least have an escape hatch right now if they run into it.
currently they have nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create an entirely new createTreeWithTempFs
utility that could be used with the caveat that tear down logic should be run to prevent build up of temp dirs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an idea 🤔
Current Behavior
Users that build their own Nx Plugins can very easily run into issues unit testing their generators when they make use of or compose generators that make use of Inferred Tasks and Inference Plugins.
Internally, we use TempFs to create a temporary directory that can be used as the root for the unit tests to create and use a workspace.
This is not available for advanced users building their own Plugins.
Expected Behavior
Expose TempFs to aid advanced users that are creating their own Nx Plugins and generators.
Add a section to the Extending Nx -> Local Generators documentation to highlight unit testing and usage of TempFs.
Related Issue(s)
Fixes #30177