Skip to content

Commit

Permalink
Merge bc10b12 into 94334b0
Browse files Browse the repository at this point in the history
  • Loading branch information
shmilky committed Jul 9, 2020
2 parents 94334b0 + bc10b12 commit be74c9b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
33 changes: 21 additions & 12 deletions lib/index.js
Expand Up @@ -153,8 +153,9 @@ function initCtx(options) {
|| !isFileFound(targetSvc) && options.svc + ' is not found on disk'
|| !options.logPath && 'options.logPath is expected to be a path'
|| 'string' != typeof options.logPath && 'options.logPath is expected to be a path'
|| !options.readyNotice && 'options.readyNotice must be a string'
|| 'string' != typeof options.readyNotice && 'options.readyNotice must be a string'
|| !options.readyNotice && 'options.readyNotice must be either a string or a function'
|| ['string', 'function']
.indexOf(typeof options.readyNotice) && 'options.readyNotice must be either a string or a function'
|| !Array.isArray(options.args) && 'options.args must be an array'
|| 'number' != typeof options.timeout && 'options.timeout must be a number'
|| 'number' != typeof options.slow && 'options.slow must be a number'
Expand Down Expand Up @@ -183,7 +184,7 @@ function initCtx(options) {
, " - logPath - string, optional - path to logfile. default: './e2e.log'"
, " - timeout - integer, optional - timeout for server setup, default: " + defaults.timeout
, " - slow - integer, optional - slow bar indicator for server setup, default: " + defaults.timeout
, " - readyNotice - string, optional - message to expect on service output that"
, " - readyNotice - string or function, optional - message to expect on service output that"
, " indicates the service is ready. default: " + defaults.readyNotice
, " - args - array, optional, argumnets to be concatenated to the running command"
, " - term_code - string, optional, the termination message to send to the child, default: " + defaults.term_code
Expand Down Expand Up @@ -235,10 +236,11 @@ function initCtx(options) {
@param {string} ctx.sut - system under test - path to the script that
runs the target server
@param {string} ctx.logPath - path to log file
@param {string} ctx.readyNotice - output line expected on stdout of
the started target service that indicates that the service is running
@param {string|function} ctx.readyNotice - either output line expected on stdout of
the started target service that indicates that the service is running or a function that will
check that the service is up
@param {mocha.Test} test - the test context that implements .timetout(n), .slow(n) ....
@param {callback} done - callback
@param {function} done - callback
@returns {undefined}
*/
function setup(ctx, test, done) {
Expand Down Expand Up @@ -284,14 +286,21 @@ function setup(ctx, test, done) {
child.stdout.on('data', (data) => {
data = data.toString()
writeLog(data)

if (~data.indexOf(ctx.readyNotice)) {
ctx.console.log('service started: %s', ctx.args.join(' '))
done()
done = null
}
})

if ('function' == typeof ctx.readyNotice) {
ctx.readyNotice(done)
done = null
} else {
child.stdout.on('data', (data) => {
if (done && ~data.indexOf(ctx.readyNotice)) {
ctx.console.log('service started: %s', ctx.args.join(' '))
done()
done = null
}
})
}

child.on('exit', (e) => {
child.exitted = true
ctx.console.log('\n\nservice termination ended', e || 'OK')
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "e2e-helper",
"version": "0.9.4",
"version": "0.10.0",
"description": "end-to-end test helper, with facilitators for mocha",
"main": "lib",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions test/lib.test.js
Expand Up @@ -56,14 +56,14 @@ module.exports =
{ svc: 'test/fixture/svc'
, readyNotice: null
}
, m: 'options.readyNotice must be a string'
, m: 'options.readyNotice must be either a string or a function'
}
, 'options.readyNotice not a string':
{ o:
{ svc: 'test/fixture/svc'
, readyNotice: -0.431
}
, m: 'options.readyNotice must be a string'
, m: 'options.readyNotice must be either a string or a function'
}
, 'options.args not an array':
{ o:
Expand Down

0 comments on commit be74c9b

Please sign in to comment.