11require ( 'chai' ) . should ( ) ;
22var fs = require ( 'fs' ) ;
3+ var exec = require ( 'child_process' ) . exec ;
34var gitHooks = require ( '../lib/git-hooks' ) ;
45var fsHelpers = require ( '../lib/fs-helpers' ) ;
56
@@ -26,7 +27,7 @@ describe('git-hook runner', function () {
2627 } ) ;
2728
2829 it ( 'should works without hooks' , function ( done ) {
29- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
30+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
3031 code . should . equal ( 0 ) ;
3132 done ( ) ;
3233 } ) ;
@@ -44,7 +45,7 @@ describe('git-hook runner', function () {
4445 } ) ;
4546
4647 it ( 'should return an error' , function ( done ) {
47- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code , error ) {
48+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code , error ) {
4849 code . should . equal ( 1 ) ;
4950 error . should . be . ok ;
5051 done ( ) ;
@@ -62,7 +63,7 @@ describe('git-hook runner', function () {
6263 } ) ;
6364
6465 it ( 'should run it one by one' , function ( done ) {
65- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
66+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
6667 code . should . equal ( 0 ) ;
6768 hooks . forEach ( function ( name ) {
6869 var logFile = SANDBOX_PATH + name + '.log' ;
@@ -76,20 +77,42 @@ describe('git-hook runner', function () {
7677 describe ( 'and work without errors' , function ( ) {
7778 var logFile = SANDBOX_PATH + 'hello.log' ;
7879 beforeEach ( function ( ) {
79- createHook ( PROJECT_PRECOMMIT_HOOK + 'hello' , 'echo "Hello, world! ${@:1}" > ' + logFile ) ;
80+ createHook (
81+ PROJECT_PRECOMMIT_HOOK + 'hello' ,
82+ 'input=`cat`; echo -e "Hello, world!\n${@:1}\n$input" > ' + logFile
83+ ) ;
8084 } ) ;
8185
8286 it ( 'should pass all arguments to them' , function ( done ) {
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 ' ) ;
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!' ) ;
8589 done ( ) ;
8690 } ) ;
8791 } ) ;
8892
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+
89112 it ( 'should run a hook with success status' , function ( done ) {
90- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
113+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
91114 code . should . equal ( 0 ) ;
92- fs . readFileSync ( logFile ) . toString ( ) . should . equal ( 'Hello, world! \n ' ) ;
115+ fs . readFileSync ( logFile ) . toString ( ) . trim ( ) . should . equal ( 'Hello, world!' ) ;
93116 done ( ) ;
94117 } ) ;
95118 } ) ;
@@ -101,7 +124,7 @@ describe('git-hook runner', function () {
101124 } ) ;
102125
103126 it ( 'should run a hook and return error' , function ( done ) {
104- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
127+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
105128 code . should . equal ( 255 ) ;
106129 done ( ) ;
107130 } ) ;
@@ -119,7 +142,7 @@ describe('git-hook runner', function () {
119142 } ) ;
120143
121144 it ( 'should ignore file with wrong permissions in hooks directory' , function ( done ) {
122- gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , function ( code ) {
145+ gitHooks . run ( PRECOMMIT_HOOK_PATH , [ ] , '' , function ( code ) {
123146 code . should . equal ( 0 ) ;
124147 done ( ) ;
125148 } ) ;
0 commit comments