Skip to content

feat: add fixture filename support#1559

Merged
ovidiuch merged 7 commits intoreact-cosmos:mainfrom
ThaisRobba:thais-robba#add-fixture-filename-support
Nov 25, 2023
Merged

feat: add fixture filename support#1559
ovidiuch merged 7 commits intoreact-cosmos:mainfrom
ThaisRobba:thais-robba#add-fixture-filename-support

Conversation

@ThaisRobba
Copy link
Contributor

Update adding support for fixture filenames, like so:

Input Output
Captura de Tela 2023-11-08 às 12 48 25 Captura de Tela 2023-11-08 às 12 48 05

Added/modified tests and also manually tested with examples, tried to keep surface changes minimal.

@ovidiubute Please, let me know if it looks good or if there is anything you'd rather see done differently or if this would not be a desired change.

@ThaisRobba ThaisRobba force-pushed the thais-robba#add-fixture-filename-support branch from 5887c09 to bda466e Compare November 15, 2023 18:52
@ThaisRobba ThaisRobba requested a review from ovidiuch November 15, 2023 18:52
@ThaisRobba
Copy link
Contributor Author

Corrected extraneous change and rebased to match new documentation ^^

}

function toCapitalCase(a: string) {
return a.replace(/^./, a[0].toUpperCase());
Copy link
Member

Choose a reason for hiding this comment

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

This might introduce unwanted results in the tree view in some cases. Here's what I mean.

Before, if you had something like main-menu/MainMenu.fixture.tsx, we'd use the fixture module name for the fixture name, and it would end up as MainMenu in Cosmos. Or if your project used all kebab case, main-menu/main-menu.fixture.tsx would end up as main-menu in Cosmos.

With this change, the folder name is used (which of course is the only option when you use the /fixture.tsx pattern), and the first letter is capitalized.

So main-menu/MainMenu.fixture.tsx becomes Main-menu in Cosmos. We could use a kebab case to camel case helper, but I don't think we want that assumption for all folks. Maybe the fixture should show as main-menu in Cosmos to follow the component folder name. We could add additional Cosmos config options here but as you know I'd like to keep it simple and find a convention that's reasonable in most cases and basically follow the user's file system.

So what do you think? Would it work for you if we kept the folder name unchanged in the tree view?

  • So in the old scenario: main-menu/MainMenu.fixture.tsx ends up as MainMenu.
  • So your new scenario: main-menu/fixture.tsx ends up as main-menu.
  • And if you use camel case for folders, too: MainMenu/fixture.tsx ends up as MainMenu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes a lot of sense - I was concerned using the folder name would break things (like how dashboard/Dashboard.fixture.tsx would become dashboard if using the folder name).

I made a modification that keeps the old behavior and uses the folder name only when the fixture is "unnamed", ie: fixture.tsx

What do you think of it?
I would be ok with folder name, I just don't want to greatly break anything for others xD

Copy link
Member

@ovidiuch ovidiuch Nov 22, 2023

Choose a reason for hiding this comment

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

Looks good to me now. Thanks for making the change!

One minor thing: Would you mind reverting the todo app example modules to what they were before? The unit tests should offer enough coverage for the old and new behavior.

While I've also used this pattern in the past, I personally like to stay away from using generic file names in my projects, like "index" (or "fixture" in this case), simply because when I do a file search (cmd + p in VS Code), or when I have tabs, they are harder to distingush. I'm sure with the right IDE config you can work around this but this is my personal preference at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem, I'm reverting the commit that changed the example code ^^

@ovidiuch ovidiuch merged commit 18af053 into react-cosmos:main Nov 25, 2023
@ovidiuch
Copy link
Member

@ThaisRobba Thanks for making this contribution!

FYI added a small change and improved the docs in #1575.

This has been published under 6.0.0-beta.7 or @next NPM dist tag.

Let me know if this works as expected once you upgrade in your project.

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.

2 participants