testjavascript / nodejs-integration-tests-best-practices

✅ Beyond the basics of Node.js testing. Including a super-comprehensive best practices list and an example app (March 2024)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A recipe with Mocha

goldbergyoni opened this issue · 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.

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?

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

@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

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 Yes, this was my intent - A mocha recipe with only the basic Kata (basic.tests.js)