1'use strict'; 2const common = require('../common'); 3const fixtures = require('../common/fixtures'); 4const { Worker } = require('worker_threads'); 5const assert = require('assert'); 6 7// Regression test for https://github.com/nodejs/node/issues/31777: 8// stdio operations coming from preload modules should count towards the 9// ref count of the internal communication port on the Worker side. 10 11for (let i = 0; i < 10; i++) { 12 const w = new Worker('console.log("B");', { 13 execArgv: ['--require', fixtures.path('printA.js')], 14 eval: true, 15 stdout: true 16 }); 17 w.on('exit', common.mustCall(() => { 18 assert.strictEqual(w.stdout.read().toString(), 'A\nB\n'); 19 })); 20} 21