{"id":13588607,"url":"https://github.com/httptoolkit/mockttp","last_synced_at":"2025-05-14T18:05:55.978Z","repository":{"id":37470900,"uuid":"71247996","full_name":"httptoolkit/mockttp","owner":"httptoolkit","description":"Powerful friendly HTTP mock server \u0026 proxy library","archived":false,"fork":false,"pushed_at":"2025-05-14T15:31:20.000Z","size":2883,"stargazers_count":806,"open_issues_count":40,"forks_count":94,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-14T16:45:34.783Z","etag":null,"topics":["fake-server","integration-testing","intercepting-proxy","javascript-testing","javascript-tests","mitm","mock","mock-server","proxy","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://httptoolkit.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/httptoolkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-18T12:53:41.000Z","updated_at":"2025-05-14T15:31:23.000Z","dependencies_parsed_at":"2024-01-14T17:15:20.824Z","dependency_job_id":"ada70ac2-e92c-4429-b828-667fa8e94ada","html_url":"https://github.com/httptoolkit/mockttp","commit_stats":{"total_commits":1047,"total_committers":22,"mean_commits":47.59090909090909,"dds":0.05539637058261704,"last_synced_commit":"e769890bea6deb107ecc3c97114a77747fce6ba6"},"previous_names":["pimterry/http-server-mock","pimterry/mockttp"],"tags_count":127,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fmockttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fmockttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fmockttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fmockttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/httptoolkit","download_url":"https://codeload.github.com/httptoolkit/mockttp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254191831,"owners_count":22029921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake-server","integration-testing","intercepting-proxy","javascript-testing","javascript-tests","mitm","mock","mock-server","proxy","testing","testing-tools"],"created_at":"2024-08-01T15:06:49.064Z","updated_at":"2025-05-14T18:05:50.969Z","avatar_url":"https://github.com/httptoolkit.png","language":"TypeScript","readme":"# Mockttp [![Build Status](https://github.com/httptoolkit/mockttp/workflows/CI/badge.svg)](https://github.com/httptoolkit/mockttp/actions) [![Available on NPM](https://img.shields.io/npm/v/mockttp.svg)](https://npmjs.com/package/mockttp)\n\n\u003e _Part of [HTTP Toolkit](https://httptoolkit.com): powerful tools for building, testing \u0026 debugging HTTP(S)_\n\n**Mockttp lets you intercept, transform or test HTTP requests \u0026 responses in JavaScript - quickly, reliably \u0026 anywhere.**\n\nYou can use Mockttp for integration testing, by intercepting real requests as part of your test suite, or you can use Mockttp to build custom HTTP proxies that capture, inspect and/or rewrite HTTP in any other kind of way you like.\n\nHTTP testing is the most common and well supported use case. There's a lot of tools to test HTTP, but typically by stubbing the HTTP functions in-process at the JS level. That ties you to a specific environment, doesn't truly test the real requests that you code would send, and only works for requests made in the same JS process. It's inflexible, limiting and inaccurate, and often unreliable \u0026 tricky to debug too.\n\nMockttp meanwhile allows you to do accurate true integration testing, writing one set of tests that works out of the box in node or browsers, with support for transparent proxying \u0026 HTTPS, strong typing \u0026 promises throughout, fast \u0026 safe parallel testing, and with debuggability built-in at every stage.\n\nMockttp is also battle-tested as a scriptable rewriting proxy, powering all the HTTP internals of [HTTP Toolkit](https://httptoolkit.com). Anything you can do with HTTP Toolkit, you can automate with Mockttp as a headless script.\n\n## Features\n\nLet's get specific. Mockttp lets you:\n\n* Write **easy, fast \u0026 reliable node.js \u0026 browser HTTP integration tests**\n* **Stub server responses** and **verify HTTP requests**\n* **Intercept HTTPS** too, with built-in self-signed certificate generation\n* **Mock requests inside or outside your process/tab**, including subprocesses, native code, remote devices, and more\n* **Test true real-world behaviour**, verifying the real requests made, and testing exactly how your whole stack will handle a response in reality\n* Stub direct requests as a **mock server**, or transparently stub requests sent elsewhere as an **HTTP mocking proxy**\n* **Mock HTTP in both node \u0026 browser tests with the same code** (universal/'isomorphic' HTTP mocking)\n* **Safely mock HTTP in parallel**, with autoconfiguration of ports, mock URLs and proxy settings, for super-charged integration testing\n* **Debug your tests easily**, with full explainability of all mock matches \u0026 misses, mock autosuggestions, and an extra detailed debug mode\n* Write modern test code, with promises all the way down, async/await, and **strong typing** (with TypeScript) throughout\n\n## Get Started\n\n```bash\nnpm install --save-dev mockttp\n```\n\n## Get Testing\n\nTo run an HTTP integration test, you need to:\n\n* Start a Mockttp server\n* Mock the endpoints you're interested in\n* Make some real HTTP requests\n* Assert on the results\n\nHere's a simple minimal example of all that using plain promises, Mocha, Chai \u0026 Superagent, which works out of the box in Node and modern browsers:\n\n```typescript\nconst superagent = require(\"superagent\");\nconst mockServer = require(\"mockttp\").getLocal();\n\ndescribe(\"Mockttp\", () =\u003e {\n    // Start your mock server\n    beforeEach(() =\u003e mockServer.start(8080));\n    afterEach(() =\u003e mockServer.stop());\n\n    it(\"lets you mock requests, and assert on the results\", async () =\u003e {\n        // Mock your endpoints\n        await mockServer.forGet(\"/mocked-path\").thenReply(200, \"A mocked response\");\n\n        // Make a request\n        const response = await superagent.get(\"http://localhost:8080/mocked-path\");\n\n        // Assert on the results\n        expect(response.text).to.equal(\"A mocked response\");\n    });\n});\n```\n\nThat is pretty easy, but we can make this simpler \u0026 more powerful. Let's take a look at some more fancy features:\n\n```typescript\nconst superagent = require(\"superagent\");\nrequire('superagent-proxy')(superagent);\nconst mockServer = require(\"mockttp\").getLocal();\n\ndescribe(\"Mockttp\", () =\u003e {\n    // Note that there's no start port here, so we dynamically find a free one instead\n    beforeEach(() =\u003e mockServer.start());\n    afterEach(() =\u003e mockServer.stop());\n\n    it(\"lets you mock without specifying a port, allowing parallel testing\", async () =\u003e {\n        await mockServer.forGet(\"/mocked-endpoint\").thenReply(200, \"Tip top testing\");\n\n        // Try mockServer.url or .urlFor(path) to get a the dynamic URL for the server's port\n        let response = await superagent.get(mockServer.urlFor(\"/mocked-endpoint\"));\n\n        expect(response.text).to.equal(\"Tip top testing\");\n    });\n\n    it(\"lets you verify the request details the mockttp server receives\", async () =\u003e {\n        const endpointMock = await mockServer.forGet(\"/mocked-endpoint\").thenReply(200, \"hmm?\");\n\n        await superagent.get(mockServer.urlFor(\"/mocked-endpoint\"));\n\n        // Inspect the mock to get the requests it received and assert on their details\n        const requests = await endpointMock.getSeenRequests();\n        expect(requests.length).to.equal(1);\n        expect(requests[0].url).to.equal(`http://localhost:${mockServer.port}/mocked-endpoint`);\n    });\n\n    it(\"lets you proxy requests made to any other hosts\", async () =\u003e {\n        // Match a full URL instead of just a path to mock proxied requests\n        await mockServer.forGet(\"http://google.com\").thenReply(200, \"I can't believe it's not google!\");\n\n        // One of the many ways to use a proxy - this assumes Node \u0026 superagent-proxy.\n        // In a browser, you can simply use the browser settings instead.\n        let response = await superagent.get(\"http://google.com\").proxy(mockServer.url);\n\n        expect(response.text).to.equal(\"I can't believe it's not google!\");\n    });\n});\n```\n\nThese examples use Mocha, Chai and Superagent, but none of those are required: Mockttp will work with any testing tools that can handle promises (and with minor tweaks, many that can't), and can mock requests from any library, tool or device you might care to use.\n\n## Documentation\n\n* [In-depth setup guide](docs/setup.md)\n* [API reference](https://httptoolkit.github.io/mockttp/)\n\n## Credits\n\n* Many thanks to https://github.com/vieiralucas for donating the package name!\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fmockttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttptoolkit%2Fmockttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fmockttp/lists"}