11cb0ef41Sopenharmony_ci// Flags: --no-warnings
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciconst vm = require('vm');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (new Error().stack.includes('node_modules'))
91cb0ef41Sopenharmony_ci  common.skip('test does not work when inside `node_modules` directory');
101cb0ef41Sopenharmony_ciif (process.env.NODE_PENDING_DEPRECATION)
111cb0ef41Sopenharmony_ci  common.skip('test does not work when NODE_PENDING_DEPRECATION is set');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst bufferWarning = 'Buffer() is deprecated due to security and usability ' +
141cb0ef41Sopenharmony_ci                      'issues. Please use the Buffer.alloc(), ' +
151cb0ef41Sopenharmony_ci                      'Buffer.allocUnsafe(), or Buffer.from() methods instead.';
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciprocess.addListener('warning', common.mustCall((warning) => {
181cb0ef41Sopenharmony_ci  assert(warning.stack.includes('this_should_emit_a_warning'), warning.stack);
191cb0ef41Sopenharmony_ci}));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_civm.runInNewContext('new Buffer(10)', { Buffer }, {
221cb0ef41Sopenharmony_ci  filename: '/a/node_modules/b'
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cicommon.expectWarning('DeprecationWarning', bufferWarning, 'DEP0005');
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_civm.runInNewContext('new Buffer(10)', { Buffer }, {
281cb0ef41Sopenharmony_ci  filename: '/this_should_emit_a_warning'
291cb0ef41Sopenharmony_ci});
30