aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-inspector-module.js
blob: 5f5efe4cb80061890c91dd7a6e5a565f0f488a70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';

const common = require('../common');

common.skipIfInspectorDisabled();

const assert = require('assert');
const { Session } = require('inspector');
const { inspect } = require('util');

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_CALLBACK',
      name: 'TypeError',
      message: `Callback must be a function. Received ${inspect(i)}`
    }
  );
});

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();