DEV Community

Discussion on: Why I struggle with Node

Collapse
 
twipped profile image
Jocelyn Badgley

For setting up databases to run integration tests against I've had great success using mktmp.io and its node module. It's missing a few DBs (neo4j, most notably), but launch time is less than half a second and response time is more than adequate for integration testing purposes. You can see it in use here: github.com/ChiperSoft/mysequel/blo...

For handling external APIs in integration tests I've used nock-vcr-recorder successfully. The first time the test passes it records all the http requests performed and stores them in json files, which then get replayed on future test runs. This is super handy for running tests in CI boxes that don't have access to those services. It just can be a bit of a bear if you need to remake the recordings and the environment you created them against doesn't have the same state any more.

Finally, I highly recommend node-tap or AVA over mocha and sinon. The tests are more reliable because they don't rely on exception throwing for assertions. One of Mocha's largest flaws is that a test that performs no assertions is indistinguishable from a test that passed.

Collapse
 
grahamcox82 profile image
Graham Cox

mktmp.io looks fantastic, but it unfortunately fails one of the requirements for proper integration testing - running against local services. Having the temporary databases hosted on a cloud server means that the build cannot be run without internet access - such as from a train or plane. Certainly worth investigating though :)

nock-vcr-recorder also looks very useful, and I will certainly be adding that to my list of things to play with when I get time :)