-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow stdin to work while profiling (#276)
* Allow stdin to work while profiling * Added test
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |