feat: add fixture filename support#1559
Conversation
packages/react-cosmos-core/src/fixtureTree/flattenFixtureTree.tsx
Outdated
Show resolved
Hide resolved
5887c09 to
bda466e
Compare
|
Corrected extraneous change and rebased to match new documentation ^^ |
| } | ||
|
|
||
| function toCapitalCase(a: string) { | ||
| return a.replace(/^./, a[0].toUpperCase()); |
There was a problem hiding this comment.
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.tsxends up asMainMenu. - So your new scenario:
main-menu/fixture.tsxends up asmain-menu. - And if you use camel case for folders, too:
MainMenu/fixture.tsxends up asMainMenu.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Sure, no problem, I'm reverting the commit that changed the example code ^^
|
@ThaisRobba Thanks for making this contribution! FYI added a small change and improved the docs in #1575. This has been published under Let me know if this works as expected once you upgrade in your project. |
Update adding support for
fixturefilenames, like so: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.