-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use IncomingMessageMock for ResponseMock and SpecialPage (#1582)
* use IncomingMessageMock for ResponseMock and SpecialPage * fix tests * renames
- Loading branch information
1 parent
0749bd4
commit c3ed48a
Showing
6 changed files
with
127 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Readable } from 'stream'; | ||
|
||
export default class IncomingMessageMock extends Readable { | ||
constructor (init) { | ||
super(); | ||
|
||
this.headers = init.headers; | ||
this.trailers = init.trailers; | ||
this.statusCode = init.statusCode; | ||
this._body = this._getBody(init._body); | ||
} | ||
|
||
_read () { | ||
this.push(this._body); | ||
this._body = null; | ||
} | ||
|
||
_getBody (body) { | ||
if (!body) | ||
return new Buffer(0); | ||
|
||
const bodyStr = typeof body === 'object' ? JSON.stringify(body) : String(body); | ||
|
||
return Buffer.from(bodyStr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
export function getResponse () { | ||
return { | ||
import IncomingMessageMock from './incoming-message-mock'; | ||
|
||
export default function createSpecialPageResponse () { | ||
return new IncomingMessageMock({ | ||
_body: new Buffer(0), | ||
statusCode: 200, | ||
trailers: {}, | ||
headers: { | ||
'content-type': 'text/html', | ||
'content-length': '0' | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
export function getBody () { | ||
return new Buffer(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters