11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// Flags: --no-warnings
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// The --no-warnings flag only suppresses writing the warning to stderr, not the
51cb0ef41Sopenharmony_ci// emission of the corresponding event. This test file can be run without it.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst common = require('../common');
81cb0ef41Sopenharmony_ciprocess.noDeprecation = true;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst assert = require('assert');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction listener() {
131cb0ef41Sopenharmony_ci  assert.fail('received unexpected warning');
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciprocess.addListener('warning', listener);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciprocess.emitWarning('Something is deprecated.', 'DeprecationWarning');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci// The warning would be emitted in the next tick, so continue after that.
211cb0ef41Sopenharmony_ciprocess.nextTick(common.mustCall(() => {
221cb0ef41Sopenharmony_ci  // Check that deprecations can be re-enabled.
231cb0ef41Sopenharmony_ci  process.noDeprecation = false;
241cb0ef41Sopenharmony_ci  process.removeListener('warning', listener);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  process.addListener('warning', common.mustCall((warning) => {
271cb0ef41Sopenharmony_ci    assert.strictEqual(warning.name, 'DeprecationWarning');
281cb0ef41Sopenharmony_ci    assert.strictEqual(warning.message, 'Something else is deprecated.');
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  process.emitWarning('Something else is deprecated.', 'DeprecationWarning');
321cb0ef41Sopenharmony_ci}));
33