child-service
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -0,1 +1,7 @@ | ||
# [2.2.0](https://github.com/nknapp/node-child-service/compare/v2.1.0...v2.2.0) (2020-07-06) | ||
### Features | ||
- add option "listenOnStderr" ([bf91ed8](https://github.com/nknapp/node-child-service/commit/bf91ed8789b400806167ce733500a931732187a3)) | ||
# [2.1.0](https://github.com/nknapp/node-child-service/compare/v2.0.2...v2.1.0) (2020-07-06) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "child-service", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Start services as child-process, wait until they are ready and stop them.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -88,2 +88,3 @@ # child-service | ||
| userOptions.timeoutAfterSignal | <code>number</code> | how long (in milliseconds) to wait after stopping the child with SIGTERM, before using SIGKILL and after that before giving up. | | ||
| userOptions.listenOnStderr | <code>boolean</code> | (default: false) whether to wait for "readyRegex" on stderr of the child-process instead of stdout | | ||
@@ -90,0 +91,0 @@ <a name="ChildService+start"></a> |
@@ -22,2 +22,3 @@ const { waitForMatch } = require("./lib/wait-for-match"); | ||
* after that before giving up. | ||
* @param {boolean?} userOptions.listenOnStderr (default: false) whether to wait for "readyRegex" on stderr of the child-process instead of stdout | ||
* @public | ||
@@ -48,2 +49,3 @@ * @returns {Promise<ChildProcessWithoutNullStreams>} | ||
readyRegex: null, | ||
listenOnStderr: false, | ||
...this.userOptions, | ||
@@ -60,5 +62,9 @@ }; | ||
let searchedOutput = options.listenOnStderr | ||
? this.watchedChildProcess.childProcess.stderr | ||
: this.watchedChildProcess.childProcess.stdout; | ||
await Promise.race([ | ||
waitForMatch({ | ||
readable: this.watchedChildProcess.childProcess.stdout, | ||
readable: searchedOutput, | ||
regex: options.readyRegex, | ||
@@ -65,0 +71,0 @@ limit: options.outputLimit, |
@@ -48,2 +48,17 @@ const { ChildService } = require("./index"); | ||
}); | ||
it("if the matching line is written to stderr and 'listenOnStderr' is set to true", async () => { | ||
service = new ChildService({ | ||
command: process.argv0, | ||
args: ["test/children/ready-after-500ms-on-stderr.js"], | ||
readyRegex: /Now I am ready/, | ||
listenOnStderr: true, | ||
}); | ||
const { duration, result } = await measureMillis(() => service.start()); | ||
expect(result).toBeInstanceOf(ChildProcess); | ||
expect(duration).toBeGreaterThan(200); | ||
expect(duration).toBeLessThan(1000); | ||
}); | ||
}); | ||
@@ -50,0 +65,0 @@ |
@@ -17,2 +17,3 @@ declare module "child-service" { | ||
timeoutAfterSignal?: number; | ||
listenOnStderr?: boolean; | ||
} | ||
@@ -19,0 +20,0 @@ |
29501
675
120