Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdout and stderr not inherited when runtime: 'child_process' #103

Open
AriPerkkio opened this issue Oct 15, 2024 · 0 comments · May be fixed by #104
Open

stdout and stderr not inherited when runtime: 'child_process' #103

AriPerkkio opened this issue Oct 15, 2024 · 0 comments · May be fixed by #104

Comments

@AriPerkkio
Copy link
Member

AriPerkkio commented Oct 15, 2024

Vitest's reporters go crazy when we cannot control how to print worker's process.stdout and process.stderr in main thread. These can be for example NodeJS deprecation warnings.

// main.mjs
import { URL } from 'node:url'
import Tinypool from 'tinypool'

const write = process.stdout.write.bind(process.stdout)

process.stdout.write = (data) => {
  write(`Captured stdout: ${data}\n`)
}

process.stderr.write = (data) => {
  write(`Captured stderr: ${data}\n`)
}

const pool = new Tinypool({
  runtime: 'child_process',
  filename: new URL('./worker.mjs', import.meta.url).href,
})

await pool.run()

// worker.mjs
export default function run() {
  process.stdout.write('Message')
  process.stderr.write('Error message')
}
$ node main.mjs 
Message
Error message

With runtime: 'worker_threads':

$ node main.mjs 
Captured stdout: Message

Captured stderr: Error message
@AriPerkkio AriPerkkio changed the title stdout and stderr not inherited when `runtime: 'child_process' stdout and stderr not inherited when runtime: 'child_process' Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant