2016-02-12 56 views
0

我正在編寫TortoiseGIT commit hook,它應該運行nodejs/nodeunit測試,並在失敗時阻止提交。如何將nodejs/nodeunit結果傳遞迴命令行

下面是precommit.bat鉤文件(僞代碼中,不工作)

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

下面是precommit.js其中通過回調customout模塊nodeunit(除了過程工作正常。出口部分)

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); 
    } 
} 

下面是customout.js(正常工作)

exports.run =函數(文件,選項,回調){

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); 
    } 
}); 

};

什麼是從runFiles回調true/false傳遞到原始命令行進程以防止提交和通知用戶的正確方法是什麼?

回答

0

WORKING BAT

node C:\Work\perkinelmer\tests\precommit\precommit.js 
if %ERRORLEVEL% NEQ 0 (
    MSG * Some Unittests failed with errorlevel %errorlevel% 
    exit 1 
) 
1

process.exit(0)上的成功,process.exit(1)上的故障

+0

都能跟得上。我必須根據節點單元結果以某種方式在BAT中執行1號出口。 process.exit(1)在節點被鉤子忽略 –

+0

抱歉誤讀你的代碼,你已經調用了process.exit()。我認爲這是一個Windows問題 - 你怎麼能從批處理文件中獲得退出狀態。這裏有一個答案http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – akc42

+0

謝謝!鏈接幫助。 –

相關問題