react-cosmos / rfcs

Change requests for React Cosmos
MIT License
1 stars 2 forks source link

Allow fixture files and directories with the same name #25

Open angelikatyborska opened 3 years ago

angelikatyborska commented 3 years ago

What's wrong?

This is how I structure my projects:

src/Feature.tsx
src/Feature/InternalComponent1.tsx
src/Feature/InternalComponent2.tsx

With fixtures, it looks like this:

src/Feature.tsx
src/Feature.fixture.tsx
src/Feature/InternalComponent1.tsx
src/Feature/InternalComponent1.fixture.tsx
src/Feature/InternalComponent2.tsx
src/Feature/InternalComponent2.fixture.tsx

With such a structure, React Cosmos loads and displays for me the fixtures Feature/InternalComponent1 and Feature/InternalComponent2, but it doesn't display the fixture Feature. I assume that's because the other fixtures are picked up first and "block" the name Feature, preventing another fixture from being called like that.

If I rename the file from src/Feature.fixture.tsx to something else, like src/Feature_.fixture.tsx, then the fixture loads.

I can use that fact as a workaround but I would match rather have all filenames match.

User info

React Cosmos version 5.6.3, Webpack version 5.38.1.

ovidiuch commented 3 years ago

Hi @angelikatyborska,

Thanks for pointing this out. I can't be 100% sure without checking, but I believe this is by design. Another pattern that Cosmos supports is index files – src/Feature/index.tsx, which shows up as src/Feature in Cosmos. This is possibly the reason why Cosmos doesn't work as you'd want to in your case, but it doesn't necessarily mean it can't accommodate both cases with some refactor.

I've moved your issue in the RFCs repo because this sounds more like a feature request. If anyone is interested in looking into this I'm happy to help with finding the relevant code and test files.