1// Flags: --no-warnings 2'use strict'; 3 4const common = require('../common'); 5const vm = require('vm'); 6const assert = require('assert'); 7 8if (new Error().stack.includes('node_modules')) 9 common.skip('test does not work when inside `node_modules` directory'); 10if (process.env.NODE_PENDING_DEPRECATION) 11 common.skip('test does not work when NODE_PENDING_DEPRECATION is set'); 12 13const bufferWarning = 'Buffer() is deprecated due to security and usability ' + 14 'issues. Please use the Buffer.alloc(), ' + 15 'Buffer.allocUnsafe(), or Buffer.from() methods instead.'; 16 17process.addListener('warning', common.mustCall((warning) => { 18 assert(warning.stack.includes('this_should_emit_a_warning'), warning.stack); 19})); 20 21vm.runInNewContext('new Buffer(10)', { Buffer }, { 22 filename: '/a/node_modules/b' 23}); 24 25common.expectWarning('DeprecationWarning', bufferWarning, 'DEP0005'); 26 27vm.runInNewContext('new Buffer(10)', { Buffer }, { 28 filename: '/this_should_emit_a_warning' 29}); 30