Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide stream output on error #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ which causes the app to block on input when the input stream is a pipe.
Runs the `context` against the specified `context.command` and
`context.params`.

In case of error, output received on the designated stream will be available
as an array of lines as `err.stdout`.

## Example

Expand Down
17 changes: 10 additions & 7 deletions lib/nexpect.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function chain (context) {
//
return currentFn(data) === true ?
evalContext(data, '_expect') :
onError(createExpectationError(currentFn.expectation, data), true);
onError(createExpectationError(currentFn.expectation, data, stdout), true);
}
else if (currentFn.name === '_wait') {
//
Expand Down Expand Up @@ -219,12 +219,12 @@ function chain (context) {

if (!lastLine) {
onError(createUnexpectedEndError(
'No data from child with non-empty queue.', remainingQueue));
'No data from child with non-empty queue.', remainingQueue, stdout));
return false;
}
else if (context.queue.length > 0) {
onError(createUnexpectedEndError(
'Non-empty queue on spawn exit.', remainingQueue));
'Non-empty queue on spawn exit.', remainingQueue, stdout));
return false;
}
else if (!validateFnType(currentFn)) {
Expand All @@ -237,7 +237,7 @@ function chain (context) {
}
else if (currentFn.name === '_wait' || currentFn.name === '_expect') {
if (currentFn(lastLine) !== true) {
onError(createExpectationError(currentFn.expectation, lastLine));
onError(createExpectationError(currentFn.expectation, lastLine, stdout));
return false;
}
}
Expand Down Expand Up @@ -317,17 +317,19 @@ function testExpectation(data, expectation) {
}
}

function createUnexpectedEndError(message, remainingQueue) {
function createUnexpectedEndError(message, remainingQueue, stdout) {
var desc = remainingQueue.map(function(it) { return it.description; });
var msg = message + '\n' + desc.join('\n');
return new AssertionError({
var err = new AssertionError({
message: msg,
expected: [],
actual: desc
});
err.stdout = stdout;
return err;
}

function createExpectationError(expected, actual) {
function createExpectationError(expected, actual, stdout) {
var expectation;
if (util.isRegExp(expected))
expectation = 'to match ' + expected;
Expand All @@ -339,6 +341,7 @@ function createExpectationError(expected, actual) {
actual: actual,
expected: expected
});
err.stdout = stdout;
return err;
}

Expand Down