Scaffold generator does not generate stories or tests

After generating several scaffolds for our app, I noticed that it generates very little testing and no stories. The only test that gets generated is for the api service. I know when you generate the individual items, they generate both stories and tests.

My issue is that this sets an undesirable pattern for those using the scaffolding generator.

  1. Short term: Is there a way to backfill these tests without manually creating them?
  2. Long term: Is there a plan to have the scaffolding create these missing items?

I can think of two ways to fix this for the long term:

  1. Add the missing files into the scaffolding templates and generation system.
  2. Change the scaffolding system to use the individual generator templates to generate scaffolding.

Personally I like option #2, but I would assume that is much more work. It would be nice so the templates aren’t duplicated and exist in one place. It would also be nice when a developer overrides the built in templates with their own.

1 Like

We had several discussions about this when we first started integrating Jest and Storybook. Our thought was that most folks will end up customizing or throwing away the scaffolded pages as they build out their app. Several of us on the core team are seasoned Rails developers (the framework that inspired the scaffold generators) and none of us had used the Rails scaffold generators in years. It’s very impressive for new developers, or when rapidly prototyping something, but once you’re used to the framework and know what you’re doing they seemed much less useful.

If you do keep them, they’ll almost certainly be customized at some point, and it won’t take hardly any changes before the test suite and/or the generated stories completely break, which can frustrating or scary for a new dev.

If you know you’re going to keep generating scaffolds and keep them around, you can customize the generated templates, including the test and stories files, so that any future scaffolds you create will have those files fully built out. But I don’t think we’re going to make that the default in the framework in the near future.

2 Likes

I too am a long term Rails developer and rarely used scaffolding, mostly because the applications I was working on were all very custom. That said scaffolding works well as a good starting spot for admin CRUD, which is what I was currently doing with it. (Especially since there isn’t an ActiveAdmin/Administrate type gem that I know of)

While I agree that having the generated stories/tests breaking can be scary for new devs, I think not having them and not having to worry about them establishes a poor pattern. From my perspective, one of the first places a change should occur is in the test. Then refining the story to make sure it plays nicely with the changes.

I guess it really depends on what your target audience needs. If it is for quickly prototyping or new developers, then refining the scaffolding makes sense to me. But I understand only so much time and effort to spend on various things.

Are you against adding tests/stories to the scaffolding? I may be up for contributing if it would be of interest. Otherwise I can create custom templates as you said.

Thanks for your time!

2 Likes

That fact that you’re willing to create a PR is definitely helping! :wink: I’ll bring it up at the next core team meeting and let you know what everyone thinks!

Normally there’s one every Tuesday but I think we’re going to skip the next one as several folks are out of the office, but the one after that should be on.

3 Likes

That would be awesome. This is my list of things I would like to address with scaffolding templates:

  • Layout with fixed Call-to-Action, be nice if call to action was dependent on page
  • Handle relationships: Many-to-One, Many-to-Many (probably not this, but putting it here just in case I have an epiphany)
  • Add MetaTag titles to appropriate pages/components
  • Add tests and stories
1 Like

The generators actually do create a test and story file – at least yarn rw g component <name> does (unless we changed this recently).

Perhaps you are referring to a different command?

The generated tests and stories are a nice starter but we actually deleted the stub tests since they are a simple render test. You can actually get these render tests from your stories with the storybook addon interaction.

module.exports = {
  features: { modernInlineRender: true, interactionsDebugger: true },
  // Storybook essentials are baked into redwood
  addons: ['@storybook/addon-interactions'],
}
2 Likes

I was specifically talking about the scaffold generator.

(side note: Michael asked this same question when he first started using Redwood, so I nudged him to see what he thought now that he’s been building for a while…)

@MichaelrMentele This question is specifically for the yarn rw g scaffold [model] command (where you get all the API/UI CRUD).

If I recall correctly, when you first started using Redwood you asked the same question. But I’m wondering what you think now (or if you even use Scaffold generators anymore).

Thanks for taking time to reply.

And thank you @craineum for posting the question!

I’ll have to look, but did a paginated sortable/filterable/searchable data grid ever get bundled into scaffolds? All the boilerplate that goes into writing that for admin pages is a massive time sink. I’m finally to the point in a project that I’m doubling back to throw time into Redwood and that was one of the things I remember needing to research further was which feature rich data grid library/component I’d want to use for this task and which ui library to use to render it all. It wasn’t a deal breaker that it wasn’t there day 1, but it would be SO nice to have something I could feed a JSONSpec to or something like that and it just whips me up a new/update form and a rich paginated and/or endless scollable data grid using the spec I provided, which could then be used for any automated testing or documentation. I want that.

1 Like

Okay @craineum we had a lengthy discussion in our last core team meeting. One concern was the experience of generating 30+ new files and overloading new devs. People are already a little overwhelmed that we create so many as it is, we’re worried that tripling that amount is going to be a lot to handle. We talked about maybe prompting when creating a scaffold, asking if you also want to generate tests and stories, or maybe just compressing the file list somehow so it isn’t so long. Or, update the post-install instructions with a more friendly overview of what was created so you’re not just handed 50 files and being told “good luck!”

There was also a discussion of how much the web side tests are actually used…since all the business logic should be living in your services, api tests seemed more important, and run more frequently. Do you find that’s the case, or are you running the entire suite most of the time?

There was also an idea to just generate tests for the “important” functions, like submitting the form, with good and bad data. Most of the pages that are created just show a cell, so t he pages themselves wouldn’t necessarily need tests. How do you feel about only some files having tests and not others?

Is your concern with missing tests/stories that you actually do keep those scaffolded pages around as admin pages, and want to make sure they don’t break if a DB field is removed, for example? Are you heavily modifying them and want to make sure they stay tested? Are you a completionist and it just feels wrong not to have them? haha

We’re going to shop these same questions around with some teams we’re in contact with that are creating startups using Redwood to hear if/how they’re using scaffolds and how they feel about the lack of tests on the web site.

Sorry this took so long to get an answer that isn’t really an answer yet, but we’re definitely giving it serious consideration!