1'use strict'; 2 3const common = require('../common'); 4 5common.skipIfInspectorDisabled(); 6 7const assert = require('assert'); 8const { Session } = require('inspector'); 9const { inspect } = require('util'); 10 11const session = new Session(); 12 13assert.throws( 14 () => session.post('Runtime.evaluate', { expression: '2 + 2' }), 15 { 16 code: 'ERR_INSPECTOR_NOT_CONNECTED', 17 name: 'Error', 18 message: 'Session is not connected' 19 } 20); 21 22session.connect(); 23session.post('Runtime.evaluate', { expression: '2 + 2' }); 24 25[1, {}, [], true, Infinity, undefined].forEach((i) => { 26 assert.throws( 27 () => session.post(i), 28 { 29 code: 'ERR_INVALID_ARG_TYPE', 30 name: 'TypeError', 31 message: 32 'The "method" argument must be of type string.' + 33 common.invalidArgTypeHelper(i) 34 } 35 ); 36}); 37 38[1, true, Infinity].forEach((i) => { 39 assert.throws( 40 () => session.post('test', i), 41 { 42 code: 'ERR_INVALID_ARG_TYPE', 43 name: 'TypeError', 44 message: 45 'The "params" argument must be of type object.' + 46 common.invalidArgTypeHelper(i) 47 } 48 ); 49}); 50 51[1, 'a', {}, [], true, Infinity].forEach((i) => { 52 assert.throws( 53 () => session.post('test', {}, i), 54 { 55 code: 'ERR_INVALID_CALLBACK', 56 name: 'TypeError', 57 message: `Callback must be a function. Received ${inspect(i)}` 58 } 59 ); 60}); 61 62assert.throws( 63 () => session.connect(), 64 { 65 code: 'ERR_INSPECTOR_ALREADY_CONNECTED', 66 name: 'Error', 67 message: 'The inspector session is already connected' 68 } 69); 70 71session.disconnect(); 72// Calling disconnect twice should not throw. 73session.disconnect(); 74