Java background is probably biasing me, but I don't like this. It interferes with my ability to find code because the file list in every directory is twice as large.
What are the benefits of putting it together?
Java background is probably biasing me, but I don't like this. It interferes with my ability to find code because the file list in every directory is twice as large.
What are the benefits of putting it together?
Component
- index.js
- Component.js
- component.scss
- Component.spec.js
This structure has worked really well for me, you have everything you need in a single directory so you don't have to jump around to another directory to find the test or styling or whatever.
Then I tried GO. GO puts them together. I was amazed at how such a simple concept could keep my code so much better organized. I could immediately open both the code and the unit tests for said code. Just don't put a ton of files in any one directory (if you have a lot of files in a directory you're actively coding it I'd argue your file structure is not optimal).
Now when I do JavaScript development I have adopted 3 extensions:
- .aspec.js is for unit tests that should work in all environments
- .nspec.js is for unit tests that only work in node.js
- .cspec.js is for unit tests that only work on a client like a web browser
If you're board you can poke at some of my open source projects that use this pattern https://github.com/KrisSiegel/msngr.js
a) forces parity between your code structure and test structure.
b) restructuring takes potentially half the time.
c) easily see and navigate to tests for a file.
d) less named things in your project since you aren't duplicating your structure.
If your directories are getting too lengthy to look at with tests in them, you should restructure them.
Edit: formatting and additional reason.