Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS: test code vs. production code organization

From a cursory look in several node.js projects on Github I noticed that the common convention is to put test files under a ./spec directory (exact name may vary: ./tests, ./specs, etc.). Let's call this the "classic" project organization.

On the other hand, there is also (at least theoretically) the "localizing" organization: each test file is in the same directory as the production file it tests (e.g., under ./controllers we will have login_controller.js as well as login_controller.spec.js).

In order to avoid theological battles on this clearly subjective topic I will ask concrete questions:

  • Has anyone saw major modules/apps using the localizing organization?
  • Are there hard drawbacks/limitations to the localizing organization? by "hard" I mean something along the lines of "well, Heroku does not include the specs/ directory in its deployment bundle (a.k.a slug) so the classic organization has a smaller footprint on the server".
  • Are there testing frameworks (Mocha, jasmine-node, and co.) that somehow impose the "classic" scheme?
like image 216
Itay Maman Avatar asked Sep 26 '26 19:09

Itay Maman


1 Answers

  1. No, but that is up to your organizational preference. I personally would prefer a test directory.
  2. Nope. Heroku includes everything in your slug that it receives, the only things that are excluded are the ones excluded from git in your .gitignore file.
  3. Not 100% sure, but generally no, test frameworks do not impose a structure on your code. They simply provide the tools for you to write your tests using the structure you want.
like image 121
TJC Avatar answered Sep 29 '26 12:09

TJC