This is a simple skeleton using of the shelf components to allow for easy declarative integration testing. I specially like the declarative nature how tests are setup and the whole environment is bootstrapped.
To acomplish this it implements an integration test harness in order to test a service that depends itself on an external service.
The external service is declared as express application with stubbed or faked responses.
The service under test is also implemented as express application but in theory can be any HTTP service implementation.
The driver of the integration test is mocha a node.js testing framework.
Let’s assume a client application needs to contact an intermediate broker web service to request a widget from a third party web service.
The following sequence diagram should clarify the flow:
The client is simulated by mocha using superagent. The ws is the web service that is going to be tested, in this case for ease of use it’s also an express application. And finally the third party endpoint other_ws is faked through express with stubbed responses.
- node.js
- npm
- mocha
- express
- supertest
- optional: strace
Depends: apt-get install nodejs mocha
mocha [debug] -R spec spec.js
strace was used to debug conditions that crashed node.js 1.0.29 on Debian Jessie without useful stack traces.
strace -f -o mocha.strace.dump mocha --reporter spec --check-leaks --globals i spec.js | grep bind --color