-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move hijackstdio out of require('common')
Move the hijackstdio functions out of common so that they are imported only into the tests that actually need them PR-URL: #22462 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
Showing
13 changed files
with
146 additions
and
96 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,33 @@ | ||
/* eslint-disable node-core/required-modules */ | ||
'use strict'; | ||
|
||
// Hijack stdout and stderr | ||
const stdWrite = {}; | ||
function hijackStdWritable(name, listener) { | ||
const stream = process[name]; | ||
const _write = stdWrite[name] = stream.write; | ||
|
||
stream.writeTimes = 0; | ||
stream.write = function(data, callback) { | ||
try { | ||
listener(data); | ||
} catch (e) { | ||
process.nextTick(() => { throw e; }); | ||
} | ||
|
||
_write.call(stream, data, callback); | ||
stream.writeTimes++; | ||
}; | ||
} | ||
|
||
function restoreWritable(name) { | ||
process[name].write = stdWrite[name]; | ||
delete process[name].writeTimes; | ||
} | ||
|
||
module.exports = { | ||
hijackStdout: hijackStdWritable.bind(null, 'stdout'), | ||
hijackStderr: hijackStdWritable.bind(null, 'stderr'), | ||
restoreStdout: restoreWritable.bind(null, 'stdout'), | ||
restoreStderr: restoreWritable.bind(null, 'stderr') | ||
}; |
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
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
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.