1'use strict'; 2 3const common = require('../common'); 4 5const assert = require('assert'); 6const { Worker, isMainThread } = require('worker_threads'); 7 8if (isMainThread) { 9 const w = new Worker(__filename, { 10 stdin: true, 11 stdout: true, 12 stderr: true 13 }); 14 15 const { stdin, stdout, stderr } = w; 16 17 w.on('exit', common.mustCall((code) => { 18 assert.strictEqual(code, 0); 19 20 // `postMessage` should not throw after termination 21 // (this mimics the browser behavior). 22 w.postMessage('foobar'); 23 w.ref(); 24 w.unref(); 25 26 // Sanity check. 27 assert.strictEqual(w.threadId, -1); 28 assert.strictEqual(w.stdin, stdin); 29 assert.strictEqual(w.stdout, stdout); 30 assert.strictEqual(w.stderr, stderr); 31 })); 32} else { 33 process.exit(0); 34} 35