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

run() got executed twice? #12

Open
cxyokk opened this issue Jan 9, 2014 · 2 comments
Open

run() got executed twice? #12

cxyokk opened this issue Jan 9, 2014 · 2 comments

Comments

@cxyokk
Copy link

cxyokk commented Jan 9, 2014

So i clone the repo, and edit the example echo.js like this:

nexpect.spawn("echo", ["xxx"]) // echo something wrong
       .expect("hello")        // this should fail
       .run(function (err) {
          console.log(arguments); // here
          if (!err) {
            console.log("hello was echoed");
          }
       });

However i still got hello was echoed. The output is:

{ '0': [Error: xxx was not expected..] }
{ '0': null, '1': [ 'xxx' ], '2': 0 }
hello was echoed

This is wrong, right?

@sam-github
Copy link
Contributor

I noticed the same. I'm not sure what intention with the run callback is.

Some of its args are things known only after child has exited, but it also is called immediately when an expectation fails. Possible correct behaviours are to, after an expectation has failed, not call it again (but in that case you don't really know when the child process is exited, which can be important to wait for before running another child). Another possibility is to when an expectation fails, save the err, terminate the child, and then call run once, but with the saved error.

Thoughts?

@xiongjia
Copy link

I just verified it:

  • It is not "execute twice"
  • The first callback is, the "expect" function get an error; The second callback is the process exited.
  • Please check the document of "run" function:
    • callback {function} Called when child process closes, with arguments
      • err {Error|null} Error if any occurred
      • output {Array} Array of lines of output examined
      • exit {Number|String} Numeric exit code, or String name of signal

The second result is, the "err, stdout, exit code / signal " of the child process and it is just told caller the child process exited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants