diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-03-22 00:30:21 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-10 00:43:41 +0200 |
commit | 9d4ab9011796902a086ca12b0a18088e2fb35cd4 (patch) | |
tree | 9e8e5076a53ce845af0c9a0893d5e7482c4ad227 /test/parallel/test-buffer-constructor-node-modules-paths.js | |
parent | e048b1552363df05d21ef3fa0054d9ab6b801df4 (diff) | |
download | android-node-v8-9d4ab9011796902a086ca12b0a18088e2fb35cd4.tar.gz android-node-v8-9d4ab9011796902a086ca12b0a18088e2fb35cd4.tar.bz2 android-node-v8-9d4ab9011796902a086ca12b0a18088e2fb35cd4.zip |
buffer: do deprecation warning outside `node_modules`
In addition to `--pending-deprecation`, emit a deprecation warning
for usage of the `Buffer()` constructor for call sites that are outside
of `node_modules`.
The goal of this is to better target developers, rather than
burdening users with an omnipresent and quickly ignored warning.
This implements the result of a TSC meeting discussion
from March 22, 2018.
PR-URL: https://github.com/nodejs/node/pull/19524
Refs: https://github.com/nodejs/node/issues/19079#issuecomment-375121443
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-constructor-node-modules-paths.js')
-rw-r--r-- | test/parallel/test-buffer-constructor-node-modules-paths.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-constructor-node-modules-paths.js b/test/parallel/test-buffer-constructor-node-modules-paths.js new file mode 100644 index 0000000000..717f783511 --- /dev/null +++ b/test/parallel/test-buffer-constructor-node-modules-paths.js @@ -0,0 +1,35 @@ +'use strict'; + +const child_process = require('child_process'); +const assert = require('assert'); +const common = require('../common'); + +if (process.env.NODE_PENDING_DEPRECATION) + common.skip('test does not work when NODE_PENDING_DEPRECATION is set'); + +function test(main, callSite, expected) { + const { stderr } = child_process.spawnSync(process.execPath, ['-p', ` + process.mainModule = { filename: ${JSON.stringify(main)} }; + + vm.runInNewContext('new Buffer(10)', { Buffer }, { + filename: ${JSON.stringify(callSite)} + });`], { encoding: 'utf8' }); + if (expected) + assert(stderr.includes('[DEP0005] DeprecationWarning'), stderr); + else + assert.strictEqual(stderr.trim(), ''); +} + +test('/a/node_modules/b.js', '/a/node_modules/x.js', true); +test('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false); +test('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false); +test('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false); +test('/a.js', '/b.js', true); +test('/a.js', '/node_modules/b.js', false); +test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', true); +test('c:\\a\\node_modules\\b.js', + 'c:\\a\\node_modules\\foo\\node_modules\\x.js', false); +test('c:\\node_modules\\foo\\b.js', + 'c:\\node_modules\\foo\\node_modules\\x.js', false); +test('c:\\a.js', 'c:\\b.js', true); +test('c:\\a.js', 'c:\\node_modules\\b.js', false); |