Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Feb 28, 2025

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

@Coly010 Coly010 requested a review from a team as a code owner February 28, 2025 16:12
@Coly010 Coly010 self-assigned this Feb 28, 2025
@Coly010 Coly010 requested a review from jaysoo February 28, 2025 16:12
Copy link

nx-cloud bot commented Feb 28, 2025

View your CI Pipeline Execution ↗ for commit 0ee88b5.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 37m 41s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 17s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check --base= --he... ✅ Succeeded 9s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 2m 14s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-28 17:44:34 UTC

@Coly010 Coly010 force-pushed the core/expose-temp-fs branch from 754036d to 0ee88b5 Compare February 28, 2025 17:00
Copy link

vercel bot commented Feb 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Feb 28, 2025 5:12pm

Copy link
Collaborator

@isaacplmann isaacplmann left a 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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins Extending Nx/angular Application Generator Fail when E2eTestRunner is provided
3 participants