1'use strict'; 2// Flags: --no-warnings 3 4// The --no-warnings flag only suppresses writing the warning to stderr, not the 5// emission of the corresponding event. This test file can be run without it. 6 7const common = require('../common'); 8process.noDeprecation = true; 9 10const assert = require('assert'); 11 12function listener() { 13 assert.fail('received unexpected warning'); 14} 15 16process.addListener('warning', listener); 17 18process.emitWarning('Something is deprecated.', 'DeprecationWarning'); 19 20// The warning would be emitted in the next tick, so continue after that. 21process.nextTick(common.mustCall(() => { 22 // Check that deprecations can be re-enabled. 23 process.noDeprecation = false; 24 process.removeListener('warning', listener); 25 26 process.addListener('warning', common.mustCall((warning) => { 27 assert.strictEqual(warning.name, 'DeprecationWarning'); 28 assert.strictEqual(warning.message, 'Something else is deprecated.'); 29 })); 30 31 process.emitWarning('Something else is deprecated.', 'DeprecationWarning'); 32})); 33