node/test/parallel/test-inspector-module.js
Mohammed Keyvanzadeh 8c4b8b201a
lib: replace validator and error
Refs: https://github.com/nodejs/node/pull/41660

PR-URL: https://github.com/nodejs/node/pull/41678
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-02-05 08:36:48 -08:00

72 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const { Session } = require('inspector');
const session = new Session();
assert.throws(
() => session.post('Runtime.evaluate', { expression: '2 + 2' }),
{
code: 'ERR_INSPECTOR_NOT_CONNECTED',
name: 'Error',
message: 'Session is not connected'
}
);
session.connect();
session.post('Runtime.evaluate', { expression: '2 + 2' });
[1, {}, [], true, Infinity, undefined].forEach((i) => {
assert.throws(
() => session.post(i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message:
'The "method" argument must be of type string.' +
common.invalidArgTypeHelper(i)
}
);
});
[1, true, Infinity].forEach((i) => {
assert.throws(
() => session.post('test', i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message:
'The "params" argument must be of type object.' +
common.invalidArgTypeHelper(i)
}
);
});
[1, 'a', {}, [], true, Infinity].forEach((i) => {
assert.throws(
() => session.post('test', {}, i),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
}
);
});
assert.throws(
() => session.connect(),
{
code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
name: 'Error',
message: 'The inspector session is already connected'
}
);
session.disconnect();
// Calling disconnect twice should not throw.
session.disconnect();