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

fix(cli): Allow common custom scaffold template files #11755

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

esteban-url
Copy link
Contributor

This PR fixes #11754 by adding the ability to generate test, stories and mock files when custom scaffold templates are in use.

Right now these files are not supported/generated even if a template file is there. This PR will allow a dev to define their own test, stories and mock templates for components and/or pages and have the yarn rw g scaffold [model] command correctly generate it for them.

Please let me know what you think of it and/or it any testing is required.

Thanks!

@esteban-url esteban-url changed the title fix(cli): Allow common custom scaffold files fix(cli): Allow common custom scaffold template files Dec 7, 2024
@Tobbe Tobbe added the release:feature This PR introduces a new feature label Dec 8, 2024
@Tobbe Tobbe added this to the next-release milestone Dec 8, 2024
@Tobbe
Copy link
Member

Tobbe commented Dec 11, 2024

I like this addition. I just want to spend some time thinking about what unit tests, if any, can be added

@esteban-url
Copy link
Contributor Author

thanks @Tobbe I gave it some though, but couldn't come up with any, so I thought better to ask the team. Also, this is "user land", and a somewhat "advanced" scenario, so they've already strayed out of the path, and have accepted that they're pretty much on their own, since they ejected the generators.

It's me, I'm "they" 😅

@Tobbe
Copy link
Member

Tobbe commented Dec 27, 2024

@esteban-url I added some tests. Please take a look and edit/add as you see fit. Another thing I realized is that now when you run yarn rw setup generator scaffold it should probably also spit out template test, mock, stories etc files as well. Can you please update the code to do that?

@esteban-url
Copy link
Contributor Author

@Tobbe I've added the templates for tests, stories and mocks, I probably went a little (a lot?) beyond what you wanted tho. It now generates initial tests/mocks/stories when you run the scaffold generator itself. do let me know what you think.

I feel like it's a great addition 😁, but I'll leave the default option as it, so if you want to get those files generated you need to pass in --stories and --tests

@@ -436,6 +437,7 @@ const modelRelatedVariables = (model) => {
editableColumns,
listFormattersImports,
formattersImports,
relations,
Copy link
Contributor Author

@esteban-url esteban-url Dec 30, 2024

Choose a reason for hiding this comment

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

adds the convenience of having the relations info available in the template, so the user can access it.

Copy link
Member

Choose a reason for hiding this comment

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

Can we include this in the templates we ship with? Otherwise I'm afraid no one will realize this is available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a dummy inclusion in the NamesCell.tsx.template

In the QUERY it adds the object for the relationship

 authorId
      author {
        id
        # Add the author fields you need here
      }

I thought I would include the type and fields, but it doesn't, not sure of it makes much sense.

I'll circle back, i might be better to include the schema object. will investigate

typescript = false,
tailwind = false,
force = false,
nestScaffoldByModel,
stories,
serviceTests = true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this preserves the current operation mode, but because the DEFAULT_CONFIG (packages/project-config/src/config.ts) sets tests = true the fixtures of the test-project change. We can either unify the tests flag, keep tests for the service and use componentTests for the component tests. I think unifying the flag makes the most sense, but it might be a breaking change. @Tobbe Please advice,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

the test-project fixtures change because the tests, mocks and stories get added to components and pages

Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly I think we should have the scaffold generator generate tests and stories by default. It should also respect the https://docs.redwoodjs.com/docs/app-configuration-redwood-toml#generate settings in redwood.toml so that users can turn test and story generation off on a global level. And also the --no-tests and --no-stories cli flags for the scaffold generator

@Tobbe
Copy link
Member

Tobbe commented Jan 2, 2025

@esteban-url Can you please take a look at the failing CI test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: Custom scaffold tests, mocks and stories are not generated
2 participants