Skip to content

Instantly share code, notes, and snippets.

@amitsingh-007
Created July 4, 2020 07:03
Show Gist options
  • Save amitsingh-007/77beee2f0056bcb21ab224626b1d6556 to your computer and use it in GitHub Desktop.
Save amitsingh-007/77beee2f0056bcb21ab224626b1d6556 to your computer and use it in GitHub Desktop.
Execute command to run jest command
/*
* Use spawn instead of exec for large ouput buffer
* https://www.hacksparrow.com/nodejs/difference-between-spawn-and-exec-of-node-js-child-rocess.html
*/
const liveOuput = (command, args) => {
const childProcess = spawn(command, args, { shell: true });
childProcess.stdout.on("data", data => {
console.log(data.toString());
});
childProcess.stderr.on("data", data => {
console.log(data.toString());
});
childProcess.on("exit", code => {
console.log("[EXIT CODE]: " + code.toString());
process.exit(code);
});
childProcess.on("error", err => {
console.log("[ERROR]: ", err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment