hello internet friends -
a couple of weeks ago Elijah Insua (tmpvar) and myself were trying to work out some graceful child processes scripts and Elijah coded up this neat little project. nexpect builds on node's core spawn methods and allows developers to easily pipe data to child processes and assert the expected response. nexpect also chains, so you can compose complex terminal interactions.
here is some sample code:
var nexpect = require('./lib/nexpect').nspawn;
nexpect.spawn("echo hello")
.expect("hello")
.run(function(err) {
if (!err) {
console.log("hello was echoed");
}
});
nexpect.spawn("ls -al /tmp/undefined")
.expect("No such file or directory")
.run(function(err) {
if (!err) {
console.log("checked that file doesn't exists");
}
});
nexpect.spawn("node")
.expect("Type '.help' for options.")
.sendline("console.log('testing')")
.expect("testing")
.sendline("process.exit()")
.run(function(err) {
if (!err) {
console.log("node process started, console logged, process exited");
} else {
console.log(err)
}
});
its barely v0.1.0 right now, so I would expect it has some issues.