-
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.
promise: Add --throw-unhandled-rejection and --trace-unhandled-reject…
…ion option --throw-unhandled-rejection option can throw Exception when no unhandledRejection listener --trace-unhandled-rejection option can output error on stderr when no unhandledRejection listener
- Loading branch information
1 parent
1e4d053
commit 580ca38
Showing
6 changed files
with
149 additions
and
0 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
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
36 changes: 36 additions & 0 deletions
36
test/parallel/test-throw-default-error-unhandled-rejections.js
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,36 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
const node = process.execPath; | ||
|
||
if (process.argv[2] === 'child') { | ||
const rejectPromise = () => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => reject(new Error('Reject Promise')), 100); | ||
}); | ||
}; | ||
rejectPromise(); | ||
} else { | ||
run('--throw-unhandled-rejection'); | ||
} | ||
|
||
function run(flags) { | ||
const args = [__filename, 'child']; | ||
if (flags) | ||
args.unshift(flags); | ||
|
||
const child = spawn(node, args); | ||
let message = ''; | ||
child.stderr.on('data', (data) => { | ||
message += data; | ||
}); | ||
child.stderr.on('end', common.mustCall(() => { | ||
assert(message.match(/Reject Promise/)); | ||
})); | ||
child.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 1); | ||
})); | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
test/parallel/test-trace-default-error-unhandled-rejections.js
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,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
const node = process.execPath; | ||
|
||
if (process.argv[2] === 'child') { | ||
const rejectPromise = () => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => reject(new Error('Reject Promise')), 100); | ||
}); | ||
}; | ||
rejectPromise(); | ||
} else { | ||
run('--trace-unhandled-rejection'); | ||
} | ||
|
||
function run(flags) { | ||
const args = [__filename, 'child']; | ||
if (flags) | ||
args.unshift(flags); | ||
|
||
const child = spawn(node, args); | ||
let errorMessage = ''; | ||
child.stderr.on('data', (data) => { | ||
errorMessage += data; | ||
}); | ||
child.stderr.on('end', common.mustCall(() => { | ||
assert(errorMessage.match(/Reject Promise/)); | ||
})); | ||
child.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
const node = process.execPath; | ||
|
||
if (process.argv[2] === 'child') { | ||
const rejectPromise = () => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => reject(null), 100); | ||
}); | ||
}; | ||
rejectPromise(); | ||
} else { | ||
run('--trace-unhandled-rejection'); | ||
} | ||
|
||
function run(flags) { | ||
const args = [__filename, 'child']; | ||
if (flags) | ||
args.unshift(flags); | ||
|
||
const child = spawn(node, args); | ||
let message = ''; | ||
child.stderr.on('data', (data) => { | ||
message += data; | ||
}); | ||
child.stderr.on('end', common.mustCall(() => { | ||
assert(message.match(/null/)); | ||
})); | ||
child.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
})); | ||
} | ||
|
||
|