node/test/parallel/test-buffer-constructor-outside-node-modules.js
ZYSzys dcc5e51e1c tools: force common be required before any other modules
PR-URL: https://github.com/nodejs/node/pull/27650
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-05-13 19:39:34 +08:00

30 lines
1007 B
JavaScript

// Flags: --no-warnings
'use strict';
const common = require('../common');
const vm = require('vm');
const assert = require('assert');
if (new Error().stack.includes('node_modules'))
common.skip('test does not work when inside `node_modules` directory');
if (process.env.NODE_PENDING_DEPRECATION)
common.skip('test does not work when NODE_PENDING_DEPRECATION is set');
const bufferWarning = 'Buffer() is deprecated due to security and usability ' +
'issues. Please use the Buffer.alloc(), ' +
'Buffer.allocUnsafe(), or Buffer.from() methods instead.';
process.addListener('warning', common.mustCall((warning) => {
assert(warning.stack.includes('this_should_emit_a_warning'), warning.stack);
}));
vm.runInNewContext('new Buffer(10)', { Buffer }, {
filename: '/a/node_modules/b'
});
common.expectWarning('DeprecationWarning', bufferWarning, 'DEP0005');
vm.runInNewContext('new Buffer(10)', { Buffer }, {
filename: '/this_should_emit_a_warning'
});