How do you name test files with unit tests in NodeJS project?

Viewed 298

I have a NodeJS backend app using express framework.

I want to put my tests into a dedicated folder, say test in the root of the project. And inside that folder I am going to have two sub-folders: unit for unit tests and integration for endpoint tests.

My question is what is the common practice around naming the unit-test files when they are not co-located with the source code file that they test?

I am considering to simply reflect the file path in the test-file name by joining the path with dots, e.g. controller.products.test.js for a products.js controller code that lives under the controller folder.

But is there any common way/convention that people of NodeJS normally follow?

Here is the structure:

/
  /models
  /controllers/
    product.js
    category.js
  /middleware/
    auth.js
    validation.js
  /test/
    /unit/
      controllers.product.test.js
      middleware.auth.test.js
    /integration/
      products.test.js
  index.js
  package.json
0 Answers
Related