-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
618 additions
and
11 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
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,39 @@ | ||
'use strict'; | ||
|
||
const { Transform } = require('stream'); | ||
|
||
let hooks; | ||
let response; | ||
|
||
const abort = jest.fn(); | ||
|
||
const stream = jest.fn(() => { | ||
response = new Transform({ objectMode: true }); | ||
setImmediate(() => { | ||
const request = { abort }; | ||
response.emit('request', request); | ||
}); | ||
return response; | ||
}); | ||
|
||
const extend = jest.fn((...args) => { | ||
[{ hooks }] = args; | ||
return { stream }; | ||
}); | ||
|
||
function getMocks() { | ||
return { abort, extend, response, stream }; | ||
} | ||
|
||
function mockClear() { | ||
hooks = {}; | ||
abort.mockClear(); | ||
extend.mockClear(); | ||
stream.mockClear(); | ||
} | ||
|
||
function getHooks() { | ||
return hooks; | ||
} | ||
|
||
module.exports = { extend, getHooks, getMocks, mockClear }; |
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,15 @@ | ||
'use strict'; | ||
|
||
const { Transform } = require('stream'); | ||
|
||
function Parser() { | ||
return new Transform({ | ||
objectMode: true, | ||
transform(chunk, encoding, callback) { | ||
this.push(chunk); | ||
callback(); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { Parser }; |
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
Oops, something went wrong.