nodejs-integration-tests-best-practices icon indicating copy to clipboard operation
nodejs-integration-tests-best-practices copied to clipboard

A recipe with Mocha

Open goldbergyoni opened this issue 5 years ago • 5 comments

Clone the example app, only use Mocha instead of Jest

Before picking this issue, it's recommended to have a short tech planning chat here and only then upon sync to get up to speed.

goldbergyoni avatar Dec 08 '20 15:12 goldbergyoni

Hey,

please see what I did here.

Wasn't sure how to distinguish between mocha and jest tests - I copied the basic test recipe and added "mocha" at the end of the file name. If we go with this naming convention I think we also should add "jest" to jest's test files.

What do you think?

DanielGluskin avatar Jan 13 '21 19:01 DanielGluskin

I think that we don't need to duplicate the basic-tests for every variation. we just want to show how our startup technic is working with various libraries. so we just need to create a dummy test for mocha and focus on the configuration and how our npm t approach (all user needs to do to run the tests is git clone && npm t) is working with mocha as well

mikicho avatar Jan 16 '21 10:01 mikicho

@DanielGluskin @mikicho

I suggest that for the two difference audience, Jest and Mocha, the following should be considered:

  • Put as a recipe in a dedicated folder - Mixing this with the main example will confuse things for the Jest readers. Take the Mocha tests to a recipe. Obviously there no need to copy the system under test
  • Full example, not just setup - I think here a bit difference than Michael, Mocha reader would love to get fully working example which differs not only in setup but also in Assertion style and hooks names
  • Don't run these tests by default - Create a dedicated npm script for those (e.g. test:mocha), but don't run it by default because it will greatly slow things and make it feel like these tests are slow. Let the Mocha people run their tests only. In CI we can run both
  • I believe that the setup should happen in Mocha global setup: https://mochajs.org/#global-setup-fixtures

goldbergyoni avatar Jan 16 '21 20:01 goldbergyoni

As a mocha user, jest was very clear to me, so I'm not sure we have a lot of added value in translating ALL tests into mocha in addition. On the other hand, showing the difference (setup, syntax, assertion) does have an added value.

I think we intend to show something more general than a specific testing framework. Eventually, you can apply these practices with many different tools, even outside the scope of nodejs, so we don’t need to put an emphasis on the tools we use.

In my opinion we should create a single test file with mocha, including all setup, but not more.

DanielGluskin avatar Jan 17 '21 21:01 DanielGluskin

@DanielGluskin Yes, this was my intent - A mocha recipe with only the basic Kata (basic.tests.js)

goldbergyoni avatar Jan 17 '21 21:01 goldbergyoni