0

I am writing TortoiseGIT commit hook which should run nodejs / nodeunit tests and prevent commit if failed.

Below is precommit.bat hook file (pseudo code, NOT WORKING)

  SET RES =  node C:\Work\tests\precommit\precommit.js
  if(RES === false){
    MSG * Some tests failed!
    exit 1
 }

Below is precommit.js which passes callback to customout module for nodeunit (WORKS FINE except process.exit part)

var reporter = require('./customout');

process.chdir(__dirname);

var run_tests = [
    '../unit/HelperTests.js',
    '../unit/coreTests.Logic.js'

];


// Tell the reporter to run the tests

if(run_tests.length > 0) {
    if(arguments[0]){
        console.log("TESTS OK");
        process.exit(0);
    }else{
        console.log("TESTS FAILED");
        process.exit(1);
    }
}

Below is customout.js (WORKS FINE)

exports.run = function (files, options, callback) {

nodeunit.runFiles(paths, {
    testspec: options.testspec,
    testFullSpec: options.testFullSpec,
    moduleStart: function (name) {},
    testDone: function (name, assertions) {
        tracker.remove(name);
        }
    },
    done: function (assertions, end) {
        //passes Boolean to process.exit
        if (callback) callback(
                assertions.failures() ?
                false :
                true)
        );
    },
    testStart: function(name) {
        tracker.put(name);
    }
});

};

What is the proper way to pass true/false from runFiles callback to original Command line process in order to prevent commit and inform user?

Lev Savranskiy
  • 422
  • 2
  • 7
  • 19

2 Answers2

1

process.exit(0) on success, process.exit(1) on failure

akc42
  • 4,893
  • 5
  • 41
  • 60
  • nope. i have to do exit 1 in BAT based on nodeunit result somehow. process.exit(1) in node ignored by hook – Lev Savranskiy Feb 12 '16 at 15:19
  • sorry misread your code, you are already calling process.exit(). I think this is a windows question - how can you get at the exit status from a batch file. There is an answer here http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – akc42 Feb 12 '16 at 15:28
0

WORKING BAT

node C:\Work\perkinelmer\tests\precommit\precommit.js
if  %ERRORLEVEL% NEQ  0 (
    MSG * Some Unittests failed with errorlevel %errorlevel%
    exit 1
)
Lev Savranskiy
  • 422
  • 2
  • 7
  • 19