summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-stdio-from-preload-module.js
blob: e4178c58d46b21061a2d6f6d2605996b7c3a8a37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { Worker } = require('worker_threads');
const assert = require('assert');

// Regression test for https://github.com/nodejs/node/issues/31777:
// stdio operations coming from preload modules should count towards the
// ref count of the internal communication port on the Worker side.

for (let i = 0; i < 10; i++) {
  const w = new Worker('console.log("B");', {
    execArgv: ['--require', fixtures.path('printA.js')],
    eval: true,
    stdout: true
  });
  w.on('exit', common.mustCall(() => {
    assert.strictEqual(w.stdout.read().toString(), 'A\nB\n');
  }));
}