{"_id":"@epic-web/test-server","_rev":"7-73da6e0afeae6d88f05122d2c97958d7","name":"@epic-web/test-server","dist-tags":{"latest":"0.1.6"},"versions":{"0.1.0":{"name":"@epic-web/test-server","version":"0.1.0","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.0","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"d51d93dd2eb9d06090ab49387e0203b719ae1e1c","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.0.tgz","fileCount":9,"integrity":"sha512-RjJ2WvFepiXynHqm6svriviySVmpCA2QxJmy0DHYwy/9qjeSZvTAIttNqCLLryrV6hL+RsSpHS9CN4MSn/4DpA==","signatures":[{"sig":"MEUCIQC/XVynlmvy5amjPuqp2Y+2WV//Q3qKfvpoNZysAbMquAIgIQaagucfQ9Dg8ftLcbIuLR16LrfTsOd/tapt0jZB+Hk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":20415},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.0.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/8c038759a02d2a6f3c7d4ed77fae8a0b/epic-web-test-server-0.1.0.tgz","_integrity":"sha512-RjJ2WvFepiXynHqm6svriviySVmpCA2QxJmy0DHYwy/9qjeSZvTAIttNqCLLryrV6hL+RsSpHS9CN4MSn/4DpA==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.1","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.16.0","dependencies":{"ws":"^8.18.0","hono":"^4.5.8","@types/ws":"^8.5.12","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^2.0.5","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.0_1724418555410_0.8892248497706354","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@epic-web/test-server","version":"0.1.1","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.1","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"38cdca09df53af1c03dd0c432d1448072afbf5ee","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.1.tgz","fileCount":11,"integrity":"sha512-1/QTfJVJR34Gkd6CU1kooHqyweHVM2npm9p97yl/GGgpFgwYX/GT94wxf464Zf/L0HQx5anL6PxTDLP2oyyoBg==","signatures":[{"sig":"MEUCIQD/62w45dZOmnrz1D3wC3tOfHx0bvAUFfLpFUPsLqFAwgIgBw5A/6X4/iyrlWRI9mdjgycrg5KYuaqYV9zoF4YkRJ0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23338},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.1.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/ee7eb53812d8772347f7e84c27d6ba93/epic-web-test-server-0.1.1.tgz","_integrity":"sha512-1/QTfJVJR34Gkd6CU1kooHqyweHVM2npm9p97yl/GGgpFgwYX/GT94wxf464Zf/L0HQx5anL6PxTDLP2oyyoBg==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.2","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.19.0","dependencies":{"ws":"^8.18.0","hono":"^4.5.8","@types/ws":"^8.5.12","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^2.0.5","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.1_1745756646946_0.06747545926976217","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@epic-web/test-server","version":"0.1.2","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.2","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"594aeb4c855278071b8ae365bc1480a54b54f4f1","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.2.tgz","fileCount":12,"integrity":"sha512-vE0ZZ7xhwaw2C6pqIz4VmrFcf8KYW4hdOlemzU4l4BUO1zXJpedUoCxsauYy8SmgoMh4xS99U21VONti7k4gfw==","signatures":[{"sig":"MEUCIQCpX2rNDDIO9m3n5TZOLZ4HvvYrbJALp4IbIYQOxoD/HgIgLMp3Fwsdu8IMFcex3j2yRSFPWQWjpoHFFm2g2Xjl8YY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23601},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.2.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/7e29506b5a8f12bca804d642a30b1d4d/epic-web-test-server-0.1.2.tgz","_integrity":"sha512-vE0ZZ7xhwaw2C6pqIz4VmrFcf8KYW4hdOlemzU4l4BUO1zXJpedUoCxsauYy8SmgoMh4xS99U21VONti7k4gfw==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.2","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.19.0","dependencies":{"ws":"^8.18.0","hono":"^4.5.8","@types/ws":"^8.5.12","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^2.0.5","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.2_1745757334769_0.004930507764893344","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@epic-web/test-server","version":"0.1.3","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.3","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"55e0e1186a4616665edd5d70420159c0c738a6d5","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.3.tgz","fileCount":12,"integrity":"sha512-WeEj96dTtlsmRNNyXLPQC/n5KViJF+AUzHYKA6cGZLRpYvedNlbx/OphkXjQjoFizDWJ9nedrfmr5SiJaL+OrQ==","signatures":[{"sig":"MEUCIQDqzTy0f9UzWgCpZKs8wAw/ZnsFTevNZg4zp90S/NX2ZQIgZH1Bw/6RXLj4joq2hXn+lOjGcLXnJAqRNpvcQr/zvf0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23640},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.3.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish","postbuild":"./patch-ws-d-ts.sh"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/74dc87c36dcfc5ca76016a92ce31da85/epic-web-test-server-0.1.3.tgz","_integrity":"sha512-WeEj96dTtlsmRNNyXLPQC/n5KViJF+AUzHYKA6cGZLRpYvedNlbx/OphkXjQjoFizDWJ9nedrfmr5SiJaL+OrQ==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.2","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.19.0","dependencies":{"ws":"^8.18.0","hono":"^4.5.8","@types/ws":"^8.5.12","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^3.1.2","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.3_1745761345775_0.9786182445038025","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@epic-web/test-server","version":"0.1.4","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.4","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"fc20b148c0d817f1326a0170f8b57ae568c485cb","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.4.tgz","fileCount":12,"integrity":"sha512-8h6FDnKzh1m13e7ll2ptV5A9twkdLgDiTxj2TEsFsoXNgg6OMiycPw/PwSw4Ux9fCopD0O7jwkcEhTjYIV1pzw==","signatures":[{"sig":"MEUCIQCsenP3LjpkQJ2GliwLdnufzuszHGzZ4t3/s/b6Yd0vGQIgNMSi1JkZLSadKnUWwyRAjhwmBuSUM8TNqtc/y8VbWfI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23601},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.4.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/1755a9d2c2257dc0285f95ba1d7ba3b2/epic-web-test-server-0.1.4.tgz","_integrity":"sha512-8h6FDnKzh1m13e7ll2ptV5A9twkdLgDiTxj2TEsFsoXNgg6OMiycPw/PwSw4Ux9fCopD0O7jwkcEhTjYIV1pzw==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.2","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.19.0","dependencies":{"ws":"^8.18.1","hono":"^4.5.8","@types/ws":"^8.18.1","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^3.1.2","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.4_1745766358111_0.3864694491877798","host":"s3://npm-registry-packages-npm-production"}},"0.1.5":{"name":"@epic-web/test-server","version":"0.1.5","keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","_id":"@epic-web/test-server@0.1.5","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"homepage":"https://github.com/epicweb-dev/test-server#readme","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"dist":{"shasum":"8e570724bf2167cd01a0d77564f3ff00b910e852","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.5.tgz","fileCount":12,"integrity":"sha512-e1zv+jZ32Q7sKzC7EUYEvGkZzm5UwPIs31zHOvKB5dYLmNMdivWBR0vbr5hDVOY2h8VYfrsfUzvsaOYkhx8YPw==","signatures":[{"sig":"MEUCIQDSqWWJ+JIKJIkF7XKLgfV9rxLX2IgQB/VhEqjONrDZ+QIgN+pN3YrAMkdAKG33MQDmJVy17T+O3tHALpl3Z42mxTs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24108},"main":"./lib/index.js","type":"module","_from":"file:epic-web-test-server-0.1.5.tgz","engines":{"node":">=20"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"prettier":{"semi":false,"arrowParens":"always","singleQuote":true,"trailingComma":"all"},"_resolved":"/tmp/a8fa2d818fb7eb0b18b3010b3d39da83/epic-web-test-server-0.1.5.tgz","_integrity":"sha512-e1zv+jZ32Q7sKzC7EUYEvGkZzm5UwPIs31zHOvKB5dYLmNMdivWBR0vbr5hDVOY2h8VYfrsfUzvsaOYkhx8YPw==","repository":{"url":"git+https://github.com/epicweb-dev/test-server.git","type":"git"},"_npmVersion":"10.8.2","description":"Utility for creating HTTP and WebSocket servers for testing","directories":{},"_nodeVersion":"20.19.0","dependencies":{"ws":"^8.18.1","hono":"^4.5.8","@types/ws":"^8.18.1","@hono/node-ws":"^1.0.4","@hono/node-server":"^1.12.1","@open-draft/deferred-promise":"^2.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.2.4","undici":"^6.19.8","vitest":"^3.1.2","typescript":"^5.5.4","@types/node":"^20.0.0","@ossjs/release":"^0.8.1"},"_npmOperationalInternal":{"tmp":"tmp/test-server_0.1.5_1745771807960_0.854288071349534","host":"s3://npm-registry-packages-npm-production"}},"0.1.6":{"type":"module","name":"@epic-web/test-server","version":"0.1.6","description":"Utility for creating HTTP and WebSocket servers for testing","main":"./lib/index.js","exports":{"./http":{"types":"./lib/http.d.ts","default":"./lib/http.js"},"./ws":{"types":"./lib/ws.d.ts","default":"./lib/ws.js"},"./package.json":"./package.json"},"engines":{"node":">=20"},"keywords":["test","server","http","websocket","testing","local"],"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/epicweb-dev/test-server.git"},"publishConfig":{"access":"public"},"prettier":{"semi":false,"singleQuote":true,"trailingComma":"all","arrowParens":"always"},"dependencies":{"@hono/node-server":"^1.12.1","@hono/node-ws":"^1.0.4","@open-draft/deferred-promise":"^2.2.0","@types/ws":"^8.18.1","hono":"^4.5.8","ws":"^8.18.1"},"devDependencies":{"@ossjs/release":"^0.8.1","@types/node":"^20.0.0","tsup":"^8.2.4","typescript":"^5.5.4","undici":"^6.19.8","vitest":"^3.1.2"},"scripts":{"test":"vitest","build":"tsup","release":"release publish"},"_id":"@epic-web/test-server@0.1.6","bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"homepage":"https://github.com/epicweb-dev/test-server#readme","_integrity":"sha512-n6+dZKI2I3J8f3vjIFAYh5trgAJl0crji76+K1aoiRJqEYjdsCX/nVgBrkBCwPpBqhv9NZ1XlMqzfOafkqY5EQ==","_resolved":"/tmp/bc9cbd1e85a1276b3b6abb3f75f2e82a/epic-web-test-server-0.1.6.tgz","_from":"file:epic-web-test-server-0.1.6.tgz","_nodeVersion":"20.19.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-n6+dZKI2I3J8f3vjIFAYh5trgAJl0crji76+K1aoiRJqEYjdsCX/nVgBrkBCwPpBqhv9NZ1XlMqzfOafkqY5EQ==","shasum":"19ebf22b0b36e2bb41095be33f6a384590db6d18","tarball":"https://registry.npmjs.org/@epic-web/test-server/-/test-server-0.1.6.tgz","fileCount":12,"unpackedSize":24341,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDSLLjCMvxlnRy+HnkEGIa2V/R6FuUBy4FFq02bCm7dNQIgPz3zWd/xJ0dfBdvhOO52esC28CY5/iALFSUT5Ef/LyQ="}]},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/test-server_0.1.6_1748808698838_0.05603005698935104"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-23T13:09:15.280Z","modified":"2025-06-01T20:11:39.219Z","0.1.0":"2024-08-23T13:09:15.574Z","0.1.1":"2025-04-27T12:24:07.128Z","0.1.2":"2025-04-27T12:35:34.970Z","0.1.3":"2025-04-27T13:42:25.941Z","0.1.4":"2025-04-27T15:05:58.308Z","0.1.5":"2025-04-27T16:36:48.192Z","0.1.6":"2025-06-01T20:11:39.014Z"},"bugs":{"url":"https://github.com/epicweb-dev/test-server/issues"},"author":{"name":"Artem Zakharchenko","email":"me@kettanaito.com"},"license":"MIT","homepage":"https://github.com/epicweb-dev/test-server#readme","keywords":["test","server","http","websocket","testing","local"],"repository":{"type":"git","url":"git+https://github.com/epicweb-dev/test-server.git"},"description":"Utility for creating HTTP and WebSocket servers for testing","maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"},{"name":"kentcdodds","email":"me@kentcdodds.com"},{"name":"epic-web-bot","email":"me+epic-web-bot@kentcdodds.com"}],"readme":"# Test Server\n\nUtility for creating HTTP and WebSocket servers for testing.\n\n## Features\n\n- **Compact**. Spawn servers on-demand while keeping the test setup to the minimum.\n- **Automatically disposable**. This utility is build with the [`using`](https://www.totaltypescript.com/typescript-5-2-new-keyword-using) keyword in mind. Any servers you spawn are automatically closed once nothing is using them.\n- **Standard-based**. Handle requests and responses using the web standards. This library uses [Hono](https://hono.dev/) to spawn servers.\n\n## Install\n\n```sh\nnpm install @epic-web/test-server\n```\n\n## Usage\n\n### HTTP server\n\n```ts\nimport { createTestHttpServer } from '@epic-web/test-server/http'\n\nit('fetches the list of numbers', async () => {\n  // Create a disposable \"server\" instance.\n  await using server = await createTestHttpServer({\n    defineRoutes(router) {\n      router.get('/numbers', () => {\n        return Response.json([1, 2, 3])\n      })\n    }\n  })\n\n  // Construct URLs relatively to the test server.\n  const response = await fetch(server.http.url('/numbers'))\n  await expect(response.json()).resolves.toEqual([1, 2, 3])\n})\n```\n\n### WebSocket server\n\n```ts\nimport { createTestHttpServer } from '@epic-web/test-server/http'\nimport { createWebSocketMiddleware } from '@epic-web/test-server/ws'\n\nit('handles WebSocket communication', async () => {\n  await using server = await createTestHttpServer()\n  // Attach WebSockets as a middleware to an existing HTTP server.\n  await using wss = createWebSocketMiddleware({ server })\n\n  // Handle WebSocket connections.\n  wss.ws.on('connect', (socket) => console.log('new connection!'))\n\n  const client = new WebSocket(wss.ws.url())\n})\n```\n\n## API\n\n### `createTestHttpServer([options])`\n\nCreates an HTTP server instance.\n\n- `options` (optional)\n  - `protocols`, (optional) `Array<'http' | 'https'>` (default: `['http']`), the list of protocols to use when spawning the test server. Providing multiple values will spawn multiple servers with the corresponding controls via `server.http` and `server.https`.\n  - `defineRoutes`, (optional) `(router: Router) => void`, a function describing the server's routes.\n- Returns: [Promise<`TestHttpServer`>](#testhttpserver)\n\n### `TestHttpServer`\n\n#### `TestHttpServer.http.url([pathname])`\n\n- `pathname` (optional, default: `/`), `string`, a pathname to resolve against the server's URL.\n- Returns: `URL`.\n\nCalling the `.url()` method without any arguments returns this server's URL:\n\n```ts\nserver.http.url() // URL<http://localhost:56783/>\n```\n\nProviding the `pathname` argument returns a URL for that path:\n\n```ts\nserver.http.url('/resource') // URL<http://localhost:56783/resource>\n```\n\n#### `TestHttpServer.close()`\n\nCloses the HTTP server, aborting any pending requests.\n\n> [!IMPORTANT]\n> The `createTestHttpServer()` is a _disposable_ utility. It means that JavaScript will automatically dispose of the server instance (i.e. close it) when nothing else is referencing the `server` object. _You don't have to manually close the server_. But you _can_ close the server amidst a test, if that's what your test needs.\n\n### `createWebSocketMiddleware(options)`\n\n- `options`\n  - `server`, [`TestHttpServer`](#testhttpserver), a reference to the existing test HTTP server object.\n- Returns: [TestWebSocketServer](#testwebsocketserver)\n\n> Note: The WebSocket middleware will automatically attach itself to all spawned HTTP servers. If you are using multiple servers at once (e.g. HTTP + HTTPS), both `wss.ws` and `wss.wss` APIs will be available for WebSockets respectively.\n\n### `TestWebSocketServer`\n\n#### `TestWebSocketServer.on(type, listener)`\n\nAdds a listener for the given event.\n\n```ts\nwss.ws.on('connection', () => {})\nwss.wss.on('connection', () => {})\n```\n\n#### `TestWebSocketServer.once(type, listener)`\n\nAdds a one-time listener for the given event.\n\n#### `TestWebSocketServer.off(type, listener)`\n\nRemoves a listener from the given event.\n","readmeFilename":"README.md"}