• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4common.skipIfInspectorDisabled();
5
6const assert = require('assert');
7const { NodeInstance } = require('../common/inspector-helper.js');
8
9function mainContextDestroyed(notification) {
10  return notification.method === 'Runtime.executionContextDestroyed' &&
11      notification.params.executionContextId === 1;
12}
13
14async function runTest() {
15  const child = new NodeInstance(['--inspect-brk=0', '-e', 'process.exit(55)']);
16  const session = await child.connectInspectorSession();
17  const oldStyleSession = await child.connectInspectorSession();
18  await oldStyleSession.send([
19    { method: 'Runtime.enable' }]);
20  await session.send([
21    { method: 'Runtime.enable' },
22    { method: 'NodeRuntime.notifyWhenWaitingForDisconnect',
23      params: { enabled: true } },
24    { method: 'Runtime.runIfWaitingForDebugger' }]);
25  await session.waitForNotification((notification) => {
26    return notification.method === 'NodeRuntime.waitingForDisconnect';
27  });
28  const receivedExecutionContextDestroyed =
29    session.unprocessedNotifications().some(mainContextDestroyed);
30  if (receivedExecutionContextDestroyed) {
31    assert.fail('When NodeRuntime enabled, ' +
32      'Runtime.executionContextDestroyed should not be sent');
33  }
34  const { result: { value } } = await session.send({
35    method: 'Runtime.evaluate', params: { expression: '42' }
36  });
37  assert.strictEqual(value, 42);
38  await session.disconnect();
39  await oldStyleSession.waitForNotification(mainContextDestroyed);
40  await oldStyleSession.disconnect();
41  assert.strictEqual((await child.expectShutdown()).exitCode, 55);
42}
43
44runTest().then(common.mustCall());
45