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