Integration Tests under Node.js Environment using a mock server

Updated: Jun 27, 2019




This week, I was handed a nice task – to integrate with some external service we use, that has no API. All communication with the service was supposed to be mimicking a multiple step scenario of a user integrating with some forms. This means, cookies, sessions, and all the wonders of HTTP protocol..

And, just to add giggles, the whole component is to be written in and act as a part of a NodeJS server.

So, I thought to myself, first thing first; I configured a new NodeJs project with a Jasmine test environment, and started writing my integration tests.

But unfortunately, not only my remote service had no API, there was no way I could create an embedded local service for me to test against!

Popped up Fiddler (or Charles, whatever..) and sniffed the HTTPS traffic as I filled in the forms (Fiddler does it quite elegantly), and created a spec, specifying how should each and every packed look like.

To test it, I created a little HTTP service module, that can store its last request and even stub a response behavior.

It supports HTTP and HTTPS, and made my life easy.

Here is some usage examples:

Setting it up:


And making the actual test:



Photo by Sime Basioli on Unsplash

0 views
  • Black Twitter Icon
  • Black YouTube Icon

At Wix Engineering we develop some of the most innovative cloud-based web applications that influence our +180 million users worldwide.

Have any questions?
Email: wixeng@wix.com

Trademarks and logos of other parties appearing in this post are the property of their respective holders.

Get Wix Engineering Straight to Your e-mail