Skip to content

Commit 6997692

Browse files
committed
Revert "feat: freeze proto to work with express (#67)"
This reverts commit 7110aac.
1 parent 7110aac commit 6997692

File tree

8 files changed

+6
-128
lines changed

8 files changed

+6
-128
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ package-lock.json
5757

5858
# generated code
5959
examples/typescript-server.js
60-
test/type/index.js
61-
62-
.vscode
60+
test/type/index.js

README.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
[![Build Status](https://travis-ci.org/fastify/light-my-request.svg?branch=master)](https://travis-ci.org/fastify/light-my-request) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
66

7-
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging.
8-
Does not use a socket connection so can be run against an inactive server (server not in listen mode).
7+
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging.
8+
Does not use a socket connection so can be run against an inactive server (server not in listen mode).
99

1010
## Example
1111

@@ -131,26 +131,6 @@ The declaration file exports types for the following parts of the API:
131131
- `Request` - custom light-my-request `request` object interface. Extends Node.js `stream.Readable` type
132132
- `Response` - custom light-my-request `response` object interface. Extends Node.js `http.ServerResponse` type
133133

134-
### Example with Express
135-
136-
```javascript
137-
const http = require('http')
138-
const inject = require('light-my-request')
139-
140-
const dispatch = function (req, res) {
141-
const reply = 'Hello World'
142-
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length })
143-
res.end(reply)
144-
}
145-
146-
const server = http.createServer(dispatch)
147-
148-
inject(dispatch, { method: 'get', url: '/', express: true }, (err, res) => {
149-
console.log(res.payload)
150-
})
151-
```
152-
Note the `express: true` in the above example. This flag makes sure that we still get the correct behaviour with express framework.
153-
154134
## API
155135

156136
#### `inject(dispatchFunc[, options, callback])`
@@ -179,7 +159,6 @@ Injects a fake request into an HTTP server.
179159
- `server` - Optional http server. It is used for binding the `dispatchFunc`.
180160
- `autoStart` - Automatically start the request as soon as the method
181161
is called. It is only valid when not passing a callback. Defaults to `true`.
182-
- `express` - A boolean flag to enable working with express framework. By default express doesn't support request injection, this enforces.
183162
- `callback` - the callback function using the signature `function (err, res)` where:
184163
- `err` - error object
185164
- `res` - a response object where:
@@ -246,8 +225,8 @@ inject(dispatch)
246225
Note: The application would not respond multiple times. If you try to invoking any method after the application has responded, the application would throw an error.
247226

248227
## Acknowledgements
249-
This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*.
250-
All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors).
228+
This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*.
229+
All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors).
251230
Since the commit [db8bced](https://github.com/fastify/light-my-request/commit/db8bced10b4367731688c8738621d42f39680efc) the project will be maintained by the Fastify team.
252231

253232
## License

index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ declare namespace LightMyRequest {
5757
validate?: boolean
5858
payload?: InjectPayload
5959
server?: http.Server
60-
express?: boolean
6160
}
6261

6362
interface Request extends stream.Readable {

index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const http = require('http')
55
const Ajv = require('ajv')
66
const Request = require('./lib/request')
77
const Response = require('./lib/response')
8-
const freezeProto = require('./util')
98

109
const errorMessage = 'The dispatch function has already been invoked'
1110
const urlSchema = {
@@ -83,29 +82,18 @@ function doInject (dispatchFunc, options, callback) {
8382
}
8483
}
8584

86-
const express = options.express
8785
const server = options.server || {}
8886

8987
if (typeof callback === 'function') {
9088
const req = new Request(options)
9189
const res = new Response(req, callback)
9290

93-
if (express) {
94-
freezeProto(req)
95-
freezeProto(res)
96-
}
97-
9891
return req.prepare(() => dispatchFunc.call(server, req, res))
9992
} else {
10093
return new Promise((resolve, reject) => {
10194
const req = new Request(options)
10295
const res = new Response(req, resolve, reject)
10396

104-
if (express) {
105-
freezeProto(req)
106-
freezeProto(res)
107-
}
108-
10997
req.prepare(() => dispatchFunc.call(server, req, res))
11098
})
11199
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"types": "index.d.ts",
1111
"devDependencies": {
1212
"@types/node": "^12.11.6",
13-
"express": "^4.17.1",
1413
"form-data": "^3.0.0",
1514
"pre-commit": "^1.2.2",
1615
"standard": "^14.0.2",
@@ -20,7 +19,7 @@
2019
"scripts": {
2120
"test": "npm run lint && npm run unit && npm run tsd",
2221
"lint": "standard",
23-
"unit": "tap test/**.test.js",
22+
"unit": "tap test/test.js",
2423
"coverage": "npm run unit -- --cov --coverage-report=html",
2524
"tsd": "tsd"
2625
},

test/express.test.js

Lines changed: 0 additions & 65 deletions
This file was deleted.
File renamed without changes.

util.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)