-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node_contextify: do not incept debug context #4819
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
const util = require('util'); | ||
const payload = util.inspect({a: 'b'}); | ||
console.log(payload); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const spawn = require('child_process').spawn; | ||
const assert = require('assert'); | ||
|
||
const common = require('../common'); | ||
|
||
const fixture = path.join( | ||
common.fixturesDir, | ||
'debugger-util-regression-fixture.js' | ||
); | ||
|
||
const args = [ | ||
'debug', | ||
fixture | ||
]; | ||
|
||
const proc = spawn(process.execPath, args, { stdio: 'pipe' }); | ||
proc.stdout.setEncoding('utf8'); | ||
proc.stderr.setEncoding('utf8'); | ||
|
||
function fail() { | ||
common.fail('the program should not hang'); | ||
} | ||
|
||
const timer = setTimeout(fail, common.platformTimeout(4000)); | ||
|
||
let stdout = ''; | ||
let stderr = ''; | ||
|
||
let nextCount = 0; | ||
|
||
proc.stdout.on('data', (data) => { | ||
stdout += data; | ||
if (stdout.includes('> 1') && nextCount < 1 || | ||
stdout.includes('> 2') && nextCount < 2 || | ||
stdout.includes('> 3') && nextCount < 3 || | ||
stdout.includes('> 4') && nextCount < 4) { | ||
nextCount++; | ||
proc.stdin.write('n\n'); | ||
} | ||
else if (stdout.includes('{ a: \'b\' }')) { | ||
clearTimeout(timer); | ||
proc.stdin.write('.exit\n'); | ||
} | ||
else if (stdout.includes('program terminated')) { | ||
// Catch edge case present in v4.x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment should explain what edge case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why don't you simply throw an exception here? Moving the logic to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I have to run for now, but I'll get to this tomorrow |
||
// process will terminate after call to util.inspect | ||
common.fail('the program should not terminate'); | ||
} | ||
}); | ||
|
||
proc.stderr.on('data', (data) => stderr += data); | ||
|
||
// FIXME | ||
// This test has been periodically failing on certain systems due to | ||
// uncaught errors on proc.stdin. This will stop the process from | ||
// exploding but is still not an elegant solution. Likely a deeper bug | ||
// causing this problem. | ||
proc.stdin.on('error', (err) => { | ||
console.error(err); | ||
}); | ||
|
||
process.on('exit', (code) => { | ||
assert.equal(code, 0, 'the program should exit cleanly'); | ||
assert.equal(stdout.includes('{ a: \'b\' }'), true, | ||
'the debugger should print the result of util.inspect'); | ||
assert.equal(stderr, '', 'stderr should be empty'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to use string concatenation, call
proc.stdout.setEncoding('utf8')
first. Ditto for stderr.