Skip to content

Commit

Permalink
Added unpipe as a noop to request
Browse files Browse the repository at this point in the history
closes antongolub#29

- this adds a new type of test showing what happens when req and res are used in conjunction with express
- added a noop for unpipe, which fixes the broken test
  • Loading branch information
ErisDS committed Jan 27, 2022
1 parent fc04dc3 commit 70a96dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
} from './interface'

import express from 'express'
import { noop } from 'lodash'
import url from 'url'
import {
assign,
Expand Down Expand Up @@ -59,14 +60,17 @@ export default class Request implements IRequest {

_readableState: IAny

unpipe: Function

socket: ISocket

constructor (input: ?IRawOptions) {
setprototypeof(this, request)
const opts = new ReqOptions(input || {})

this._flush = () => {}
this._flush = noop
this._readableState = {}
this.unpipe = noop
this.socket = opts.socket
this.app = opts.app
this.res = opts.res
Expand Down
39 changes: 39 additions & 0 deletions src/test/js/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import reqresnext from '../../main/js/reqresnext'
import express from 'express'

describe('express', () => {
it('reqresnext correctly 404s when no route handlers are available', (done) => {
const { req, res } = reqresnext({
method: 'GET',
url: '/'
})

const app = express()

res.on('finish', () => {
expect(res.statusCode).toBe(404)
done()
})

app(req, res)
})

it('route handler is called when available', (done) => {
const { req, res } = reqresnext({
method: 'GET',
url: '/'
}, {})

const app = express()
app.get('/', (_req, _res) => {
return _res.sendStatus(200)
})

res.on('finish', () => {
expect(res.statusCode).toBe(200)
done()
})

app(req, res)
})
})

0 comments on commit 70a96dc

Please sign in to comment.