Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: deprecate process assert #18666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,21 @@ Certain versions of `node::MakeCallback` APIs available to native modules are
deprecated. Please use the versions of the API that accept an `async_context`
parameter.

<a id="DEP00XX"></a>
### DEP00XX: process.assert()

Type: Runtime

`process.assert()` is deprecated. Please use the [`assert`][] module instead.

This was never a documented feature.

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj
[`assert`]: assert.html
[`clearInterval()`]: timers.html#timers_clearinterval_timeout
[`clearTimeout()`]: timers.html#timers_cleartimeout_timeout
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname
Expand Down
14 changes: 9 additions & 5 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
const errors = require('internal/errors');
const util = require('util');
const constants = process.binding('constants').os.signals;

const assert = process.assert = function(x, msg) {
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
};

const assert = require('assert').strict;
const { deprecate } = require('internal/util');

process.assert = deprecate(
function(x, msg) {
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
},
'process.assert() is deprecated. Use the `assert` module instead.',
'DEP00XX');

function setup_performance() {
require('perf_hooks');
Expand Down
11 changes: 7 additions & 4 deletions test/parallel/test-process-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
const common = require('../common');
const assert = require('assert');

common.expectWarning(
'DeprecationWarning',
'process.assert() is deprecated. Use the `assert` module instead.'
);

assert.strictEqual(process.assert(1, 'error'), undefined);
common.expectsError(() => {
process.assert(undefined, 'errorMessage');
}, {
code: 'ERR_ASSERTION',
type: Error,
message: 'errorMessage'
}
);
});
common.expectsError(() => {
process.assert(false);
}, {
code: 'ERR_ASSERTION',
type: Error,
message: 'assertion error'
}
);
});