11require ( 'chai' ) . should ( ) ;
22var fs = require ( 'fs' ) ;
3- var exec = require ( 'child_process' ) . exec ;
43var gitHooks = require ( '../lib/git-hooks' ) ;
54var fsHelpers = require ( '../lib/fs-helpers' ) ;
65
@@ -27,7 +26,7 @@ describe('git-hook runner', function () {
2726 } ) ;
2827
2928 it ( 'should works without hooks' , function ( done ) {
30- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
29+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
3130 code . should . equal ( 0 ) ;
3231 done ( ) ;
3332 } ) ;
@@ -45,7 +44,7 @@ describe('git-hook runner', function () {
4544 } ) ;
4645
4746 it ( 'should return an error' , function ( done ) {
48- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code , error ) {
47+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code , error ) {
4948 code . should . equal ( 1 ) ;
5049 error . should . be . ok ;
5150 done ( ) ;
@@ -63,7 +62,7 @@ describe('git-hook runner', function () {
6362 } ) ;
6463
6564 it ( 'should run it one by one' , function ( done ) {
66- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
65+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
6766 code . should . equal ( 0 ) ;
6867 hooks . forEach ( function ( name ) {
6968 var logFile = SANDBOX_PATH + name + '.log' ;
@@ -77,42 +76,20 @@ describe('git-hook runner', function () {
7776 describe ( 'and work without errors' , function ( ) {
7877 var logFile = SANDBOX_PATH + 'hello.log' ;
7978 beforeEach ( function ( ) {
80- createHook (
81- PROJECT_PRECOMMIT_HOOK + 'hello' ,
82- 'input=`cat`; echo -e "Hello, world!\n${@:1}\n$input" > ' + logFile
83- ) ;
79+ createHook ( PROJECT_PRECOMMIT_HOOK + 'hello' , 'echo "Hello, world! ${@:1}" > ' + logFile ) ;
8480 } ) ;
8581
8682 it ( 'should pass all arguments to them' , function ( done ) {
87- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ 'I' , 'am' , 'working' , 'properly!' ] , '' , function ( ) {
88- fs . readFileSync ( logFile ) . toString ( ) . trim ( ) . should . equal ( 'Hello, world!\nI am working properly!' ) ;
83+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ 'I' , 'am' , 'working' , 'properly!' ] , function ( ) {
84+ fs . readFileSync ( logFile ) . toString ( ) . should . equal ( 'Hello, world! I am working properly!\n ' ) ;
8985 done ( ) ;
9086 } ) ;
9187 } ) ;
9288
93- describe ( 'if standard input is passed in' , function ( ) {
94- it ( 'should read it properly' , function ( done ) {
95- exec ( 'echo "I am working properly!" | ' + PRECOMMIT_HOOK_PATH , function ( ) {
96- fs . readFileSync ( logFile ) . toString ( ) . trim ( )
97- . should . equal ( 'Hello, world!\n\nI am working properly!' ) ;
98- done ( ) ;
99- } ) ;
100- } ) ;
101-
102- it ( 'should pass it to them' , function ( done ) {
103- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , 'I am working properly!' , function ( ) {
104- fs . readFileSync ( logFile ) . toString ( ) . trim ( )
105- . should . equal ( 'Hello, world!\n\nI am working properly!' ) ;
106- done ( ) ;
107- } ) ;
108- } ) ;
109-
110- } ) ;
111-
11289 it ( 'should run a hook with success status' , function ( done ) {
113- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
90+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
11491 code . should . equal ( 0 ) ;
115- fs . readFileSync ( logFile ) . toString ( ) . trim ( ) . should . equal ( 'Hello, world!' ) ;
92+ fs . readFileSync ( logFile ) . toString ( ) . should . equal ( 'Hello, world! \n ' ) ;
11693 done ( ) ;
11794 } ) ;
11895 } ) ;
@@ -124,7 +101,7 @@ describe('git-hook runner', function () {
124101 } ) ;
125102
126103 it ( 'should run a hook and return error' , function ( done ) {
127- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
104+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
128105 code . should . equal ( 255 ) ;
129106 done ( ) ;
130107 } ) ;
@@ -142,7 +119,7 @@ describe('git-hook runner', function () {
142119 } ) ;
143120
144121 it ( 'should ignore file with wrong permissions in hooks directory' , function ( done ) {
145- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
122+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
146123 code . should . equal ( 0 ) ;
147124 done ( ) ;
148125 } ) ;
0 commit comments