File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3636 },
3737 "devDependencies" : {
3838 "pre-commit" : " git://github.com/observing/pre-commit.git" ,
39+ "proxyquire" : " ^2.1.3" ,
3940 "standard" : " ^16.0.3" ,
4041 "tap" : " ^15.0.9"
4142 }
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ const Hook = require('./')
44const tty = require ( 'tty' )
55const ttySupportColor = tty . isatty ( process . stdout . fd )
66
7+ const proxyquire = require ( 'proxyquire' )
8+
79t . test ( 'pre-commit' , function ( t ) {
810 t . plan ( 5 )
911
@@ -144,25 +146,22 @@ t.test('pre-commit', function (t) {
144146 t . test ( 'overrides the `pre-commit` config property in package.json with the config inside pre-commit.json if it exists' , function ( t ) {
145147 t . plan ( 1 )
146148
147- const fs = require ( 'fs' )
148- const { existsSync, readFileSync } = fs
149-
150- fs . existsSync = function existsSyncMock ( ) {
151- return true
152- }
153-
154- fs . readFileSync = function readFileSyncMock ( ) {
155- return Buffer . from ( JSON . stringify ( { run : [ 'lint' , 'bench' ] } ) )
156- }
149+ const Hook = proxyquire ( '.' , {
150+ fs : {
151+ existsSync ( ) {
152+ return true
153+ } ,
154+ readFileSync ( ) {
155+ const rawText = JSON . stringify ( { run : [ 'lint' , 'bench' ] } )
156+ return Buffer . from ( rawText )
157+ }
158+ }
159+ } )
157160
158161 hook = new Hook ( function ( ) { } , { ignorestatus : true } )
159162
160163 // ----
161164 t . same ( hook . config . run , [ 'lint' , 'bench' ] )
162-
163- // Restoring mocks
164- fs . existsSync = existsSync
165- fs . readFileSync = readFileSync
166165 } )
167166 } )
168167
You can’t perform that action at this time.
0 commit comments