Skip to content

Commit 9e14637

Browse files
provide clarifying example of onStdOut
1 parent 6b44f8e commit 9e14637

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,26 @@ runner.runCommand(
130130
);
131131
```
132132
133-
`onStdOut` - a callback function that is invoked with a string each time the child process writes to std out. Defaults to `null`.
133+
##### onStdOut
134+
This is a callback function that is invoked with a string each time the child process writes to std out. Defaults to `null`. In conjunction with `stopCommand`, this can be useful to listen for when a long running command is "ready", like waiting for a web server to start.
135+
136+
```js
137+
before(async function () {
138+
await runner.setup(outputPath);
139+
140+
await new Promise((resolve, reject) => {
141+
runner.runCommand(
142+
'/path/to/cli.js',
143+
"develop",
144+
{ onStdOut: (message) => {
145+
if (message.includes(`Started local development server at http://localhost:8080`)) {
146+
resolve();
147+
}
148+
}}
149+
).catch(reject)
150+
});
151+
});
152+
```
134153
135154
### Runner.teardown
136155

0 commit comments

Comments
 (0)