How to read the return value from jake.exec?
AlessandroBudroni opened this issue · 2 comments
AlessandroBudroni commented
Suppose I want to run a test using
jake.exec('node test.js);
How can I know if the test was successful or not? In other words, how can I know if the script returned 0 or an error code?
busticated commented
i assume you've seen the docs on .exec
? --> http://jakejs.com/docs#running_shell-commands:_`jakeexec`_and_`jake.create_exec`_`jakeexec`
iirc, the default behavior is to exit on error and return the associated code.
as an example, here's a simple eslint task i use:
task('lint', function(){
var files = new jake.FileList(),
eslintCfg;
console.log('\n::::: Linting Project :::::');
files.include('Jakefile');
files.include('**/*.js');
files.exclude('public/');
files.exclude('node_modules');
files = files.toArray();
files.forEach(listFile);
eslintCfg = ['eslint'];
eslintCfg.push.apply(eslintCfg, files);
eslintCfg = eslintCfg.join(' ');
jake.exec(eslintCfg, { printStdout: true }, onComplete);
function listFile(file){
console.log(file);
}
function onComplete(){
console.log(`::::: Linting Passed [files: ${files.length}] :::::`);
complete();
}
}, { async: true });
when it fails, i see the following in the console:
jake aborted.
Error: Process exited with error.
at api.fail (/path/to/my/project/node_modules/jake/lib/api.js:336:18)
at Exec.<anonymous> (/path/to/my/project/node_modules/jake/lib/utils/index.js:124:9)
(See full trace by running task with --trace)
checking the return status via echo $?
shows the code 1
edit:
the key is that the process you run via .exec()
should itself exit with an appropriate status code 👍
AlessandroBudroni commented
I understand... thank you for your clarifying answer :)