power-assert
power-assert copied to clipboard
Runtime interrogation of assertions-enabled status
So, for relatively simple assertions, it's possible to keep the entire assertion within the single assert( … ) statement; but I have a few places in my code where monstrosities like the following arise:
assert( null != blah.first_complicated_state() ?
(null != blah.second_complicated_state() ?
_.every(blah, element => ...)
: _.every(blah, element => ...))
: _.every(blah, element => ...)
)
Basically, sometimes, there's an expensive operation (i.e. not something I can safely leave laying around outside the assert, to end up in production code) that's necessary to choose how to assert something else.
Since I suspect asking for a to-be-compiled-out assert { … } block is unlikely to be in-line with the project goals, can I simply get a runtime-cheap boolean-property that I can test, to preform more complicated assertions that won't be compiled-out?
if (assert.enabled) {
if (blah.first_complicated_state())
assert( ... )
else if (blah.second_complicated_state())
assert( ... )
...
}
@ELLIOTTCABLE Thank you for your feature request.
For removing development-only blocks, I recommend you to use features like Conditional compilation of UglifyJS, in conjunction with:
- Babel: babel-plugin-transform-inline-environment-variables
- Browserify: envify + uglifyify
- Webpack: DefinePlugin
With them you can remove development-only blocks safely.
Since power-assert aims to be 100% compatible and replaceable with native assert, I do not want to add property that Node's assert doesn't have.