mirror of
https://github.com/nodejs/node.git
synced 2025-05-12 00:04:15 +00:00

There is actually no reason to use `assert.doesNotThrow()` in the tests. If a test throws, just let the error bubble up right away instead of first catching it and then rethrowing it. PR-URL: https://github.com/nodejs/node/pull/18669 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const {
|
|
getSystemErrorName,
|
|
_errnoException
|
|
} = require('util');
|
|
|
|
const uv = process.binding('uv');
|
|
const keys = Object.keys(uv);
|
|
|
|
keys.forEach((key) => {
|
|
if (!key.startsWith('UV_'))
|
|
return;
|
|
|
|
const err = _errnoException(uv[key], 'test');
|
|
const name = uv.errname(uv[key]);
|
|
assert.strictEqual(getSystemErrorName(uv[key]), name);
|
|
assert.strictEqual(err.code, name);
|
|
assert.strictEqual(err.code, err.errno);
|
|
assert.strictEqual(err.message, `test ${name}`);
|
|
});
|
|
|
|
function runTest(fn) {
|
|
['test', {}, []].forEach((err) => {
|
|
common.expectsError(
|
|
() => fn(err),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "err" argument must be of type number. ' +
|
|
`Received type ${typeof err}`
|
|
});
|
|
});
|
|
|
|
[0, 1, Infinity, -Infinity, NaN].forEach((err) => {
|
|
common.expectsError(
|
|
() => fn(err),
|
|
{
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
type: RangeError,
|
|
message: 'The value of "err" is out of range. ' +
|
|
'It must be a negative integer. ' +
|
|
`Received ${err}`
|
|
});
|
|
});
|
|
}
|
|
|
|
runTest(_errnoException);
|
|
runTest(getSystemErrorName);
|