Package for high level HTTP server mocking using mitm and express. It allows making complex mock servers and APIs without actually running live servers in your unit tests. It also simplifies the process by separating the mock servers from the actual tests as oppose to libraries like nock and sinon.
This library will not intercept standard HTTP requests or TCP connections to anything other than the servers you define.
Eace server you create will have to be attached to a specific address. A basic mock will be:
var mitmServers = ;var express = ;var mockApp = ;mockApp;mitmServers;
Now, whenever you send a request to google.com, you will be routed to the files
test_static_google folder. For example:
var request = ;;
Starts intercepting requests to the given host and handling those requests with the given express app.
hostname: The target hostname as a string. You can also specific a port with
:. For example:
app: An app you've created with express or connect. Alternatively, you can use any function that handles an
Removes interceptions from the given host.
hostname: The target hostname as a string
Removes interceptions for all the hosts. Convenient for teardown functions.
If you need to mock a host that connections to it are sent with HTTPS you'll need to specifiy the SSL port for it (443). For example: