summaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-01-20 11:38:35 -0800
committerJames M Snell <jasnell@gmail.com>2016-03-24 13:19:11 -0700
commitc6656db352973d6aea24cb1a3c76adf042b25446 (patch)
treeef3468c6fb403d3dabbb3e3428ae79fb2fbfa884 /test/sequential
parentfc8542f1c0e7996cf13a9b5dd4ba9a55bc410cdd (diff)
downloadandroid-node-v8-c6656db352973d6aea24cb1a3c76adf042b25446.tar.gz
android-node-v8-c6656db352973d6aea24cb1a3c76adf042b25446.tar.bz2
android-node-v8-c6656db352973d6aea24cb1a3c76adf042b25446.zip
process: add 'warning' event and process.emitWarning()
In several places throughout the code we write directly to stderr to report warnings (deprecation, possible eventemitter memory leak). The current design of simply dumping the text to stderr is less than ideal. This PR introduces a new "process warnings" mechanism that emits 'warning' events on the global process object. These are invoked with a `warning` argument whose value is an Error object. By default, these warnings will be printed to stderr. This can be suppressed using the `--no-warnings` and `--no-deprecation` command line flags. For warnings, the 'warning' event will still be emitted by the process, allowing applications to handle the warnings in custom ways. The existing `--no-deprecation` flag will continue to supress all deprecation output generated by the core lib. The `--trace-warnings` command line flag will tell Node.js to print the full stack trace of warnings as part of the default handling. The existing `--no-deprecation`, `--throw-deprecation` and `--trace-deprecation` flags continue to work as they currently do, but the exact output of the warning message is modified to occur on process.nextTick(). The stack trace for the warnings and deprecations preserve and point to the correct call site. A new `process.emitWarning()` API is provided to permit userland to emit warnings and deprecations using the same consistent mechanism. Test cases and documentation are included. PR-URL: https://github.com/nodejs/node/pull/4782 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-deprecation-flags.js23
-rw-r--r--test/sequential/test-process-warnings.js33
2 files changed, 44 insertions, 12 deletions
diff --git a/test/sequential/test-deprecation-flags.js b/test/sequential/test-deprecation-flags.js
index 1b9521001e..35a443c2bb 100644
--- a/test/sequential/test-deprecation-flags.js
+++ b/test/sequential/test-deprecation-flags.js
@@ -1,16 +1,16 @@
'use strict';
require('../common');
-var assert = require('assert');
-var execFile = require('child_process').execFile;
-var depmod = require.resolve('../fixtures/deprecated.js');
-var node = process.execPath;
+const assert = require('assert');
+const execFile = require('child_process').execFile;
+const depmod = require.resolve('../fixtures/deprecated.js');
+const node = process.execPath;
-var depUserland =
+const depUserland =
require.resolve('../fixtures/deprecated-userland-function.js');
-var normal = [depmod];
-var noDep = ['--no-deprecation', depmod];
-var traceDep = ['--trace-deprecation', depmod];
+const normal = [depmod];
+const noDep = ['--no-deprecation', depmod];
+const traceDep = ['--trace-deprecation', depmod];
execFile(node, normal, function(er, stdout, stderr) {
console.error('normal: show deprecation warning');
@@ -34,9 +34,8 @@ execFile(node, traceDep, function(er, stdout, stderr) {
assert.equal(stdout, '');
var stack = stderr.trim().split('\n');
// just check the top and bottom.
- assert.equal(stack[0],
- 'Trace: util.debug is deprecated. Use console.error instead.');
- assert.equal(stack.pop(), 'DEBUG: This is deprecated');
+ assert(/util.debug is deprecated. Use console.error instead./.test(stack[1]));
+ assert(/DEBUG: This is deprecated/.test(stack[0]));
console.log('trace ok');
});
@@ -44,6 +43,6 @@ execFile(node, [depUserland], function(er, stdout, stderr) {
console.error('normal: testing deprecated userland function');
assert.equal(er, null);
assert.equal(stdout, '');
- assert.equal(0, stderr.indexOf('deprecatedFunction is deprecated.'));
+ assert(/deprecatedFunction is deprecated/.test(stderr));
console.error('normal: ok');
});
diff --git a/test/sequential/test-process-warnings.js b/test/sequential/test-process-warnings.js
new file mode 100644
index 0000000000..75efd53504
--- /dev/null
+++ b/test/sequential/test-process-warnings.js
@@ -0,0 +1,33 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+const execFile = require('child_process').execFile;
+const warnmod = require.resolve('../fixtures/warnings.js');
+const node = process.execPath;
+
+const normal = [warnmod];
+const noWarn = ['--no-warnings', warnmod];
+const traceWarn = ['--trace-warnings', warnmod];
+
+execFile(node, normal, function(er, stdout, stderr) {
+ // Show Process Warnings
+ assert.equal(er, null);
+ assert.equal(stdout, '');
+ assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
+});
+
+execFile(node, noWarn, function(er, stdout, stderr) {
+ // Hide Process Warnings
+ assert.equal(er, null);
+ assert.equal(stdout, '');
+ assert(!/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
+});
+
+execFile(node, traceWarn, function(er, stdout, stderr) {
+ // Show Warning Trace
+ assert.equal(er, null);
+ assert.equal(stdout, '');
+ assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
+ assert(/at Object\.\<anonymous\>\s\(.+warnings.js:3:9\)/.test(stderr));
+});