A mock HTTP server for Elixir testing that intercepts requests and returns preconfigured responses.
Bypass is an Elixir library that creates a mock HTTP server for testing HTTP clients. It allows developers to intercept requests and return preconfigured responses, simulating various server behaviors like errors, downtime, and specific routes. This enables reliable testing of client-side HTTP handling without depending on external services.
Elixir developers writing tests for HTTP clients or applications that make external HTTP requests. It's particularly useful for those needing to simulate server responses, test error handling, or verify client behavior during server downtime.
Developers choose Bypass because it provides a simple, focused way to mock HTTP servers in Elixir tests, with fine-grained control over responses and server state. It integrates seamlessly with Elixir's Plug and Cowboy, supports concurrent testing, and works with both ExUnit and ESpec.
Bypass provides a quick way to create a custom plug that can be put in place instead of an actual HTTP server to return prebaked responses to client requests.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows defining expectations for specific HTTP methods and paths using expect/4 and expect_once/4, enabling fine-grained control over server responses as shown in the TwitterClient example.
Provides Bypass.down/1 and Bypass.up/1 to simulate server going offline and recovering, useful for testing client error handling and reconnection logic.
Supports multiple concurrent Bypass instances and handles concurrent requests on the same instance, facilitating parallel test execution as mentioned in the README.
Automatically sets up on_exit hooks to close sockets and verify expectations, reducing boilerplate in tests without manual cleanup.
When using with ESpec, developers must manually call Bypass.verify_expectations! in finally blocks, adding extra steps and complexity compared to ExUnit's automatic verification.
Bypass.open/0 cannot be called in setup_all blocks due to per-test expectation verification, limiting reuse across multiple tests and potentially increasing setup time.
Primarily designed for HTTP/1.1 over TCP with Cowboy 2; may not fully support testing HTTP/2, WebSockets, or other protocols without additional workarounds.