Commit e1444d7
authored
Expose a mock socket that is an EventEmitter like a real one would be (#101)
Before this change, if a Fastify user attached an `onTimeout` hook to their server, an error would be thrown in test mode when injecting requests with light-my-request
```
TypeError: request.raw.socket.on is not a function
at Object.routeHandler [as handler] (../../node_modules/fastify/lib/route.js:350:28)
at Router.lookup (../../node_modules/find-my-way/index.js:356:14)
at ../../node_modules/light-my-request/index.js:101:38
at Request.prepare (../../node_modules/light-my-request/lib/request.js:110:12)
at ../../node_modules/light-my-request/index.js:101:11
at doInject (../../node_modules/light-my-request/index.js:97:12)
at Chain.<computed> [as then] (../../node_modules/light-my-request/index.js:187:23)
at runMicrotasks (<anonymous>)
```
This fixes the socket object to have an `on` function (as well as the rest of the EventEmitter interface) so that things that add timeout handlers can at least add them without erroring. This doesn't implement actual timeout injection, but I think that could be done in userland by emitting events on the socket manually.
Similar to #99.1 parent 009ece0 commit e1444d7
2 files changed
+29
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
28 | 42 | | |
29 | 43 | | |
30 | 44 | | |
| |||
68 | 82 | | |
69 | 83 | | |
70 | 84 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 85 | + | |
74 | 86 | | |
75 | 87 | | |
76 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
| |||
0 commit comments