summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port-inspect-during-init-hook.js
blob: 8f9678de1e970e7cb03df9d65da08628be670a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
const common = require('../common');
const util = require('util');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { MessageChannel } = require('worker_threads');

// Regression test: Inspecting a `MessagePort` object before it is finished
// constructing does not crash the process.

async_hooks.createHook({
  init: common.mustCall((id, type, triggerId, resource) => {
    assert.strictEqual(
      util.inspect(resource),
      'MessagePort [EventTarget] { active: true, refed: false }');
  }, 2)
}).enable();

const { port1 } = new MessageChannel();
const inspection = util.inspect(port1);
assert(inspection.includes('active: true'));
assert(inspection.includes('refed: false'));