Skip to content

Commit

Permalink
Allow stdin to work while profiling (#276)
Browse files Browse the repository at this point in the history
* Allow stdin to work while profiling

* Added test
  • Loading branch information
STRd6 authored Sep 4, 2023
1 parent 4abcd1e commit eb9dfd3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion platform/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function v8 (args) {
'-r', path.join(__dirname, '..', 'lib', 'preload', 'soft-exit'),
...(onPort ? ['-r', path.join(__dirname, '..', 'lib', 'preload', 'detect-port.js')] : [])
].concat(args.argv), {
stdio: ['ignore', 'pipe', 'inherit', 'pipe', 'ignore', 'pipe']
stdio: ['inherit', 'pipe', 'inherit', 'pipe', 'ignore', 'pipe']
})

// Isolate log is created before command is executed
Expand Down
12 changes: 12 additions & 0 deletions test/fixture/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

// Just echo the stdin content
const run = async () => {
const results = []
for await (const chunk of process.stdin) {
results.push(chunk)
}
return results.join('')
}

run().then((s) => process.stdout.write(s))
13 changes: 13 additions & 0 deletions test/read-stdin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { exec } = require('child_process')
const { test } = require('tap')
const fs = require('fs')

test('should be able to profile commands that expect stdin', async t => {
return new Promise((resolve, reject) => {
exec('./cmd.js test/fixture/stdin.js < test/fixture/stdin.js', (error, stdout, stderr) => {
if (error) return reject(error)
t.equal(stdout, fs.readFileSync('test/fixture/stdin.js', 'utf8'))
resolve()
})
})
})

0 comments on commit eb9dfd3

Please sign in to comment.