summaryrefslogtreecommitdiff
path: root/test/sequential/test-process-warnings.js
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/test-process-warnings.js
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/test-process-warnings.js')
-rw-r--r--test/sequential/test-process-warnings.js33
1 files changed, 33 insertions, 0 deletions
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));
+});