@@ -96,6 +96,51 @@ describe('utimes', () => {
9696 done ( )
9797 } )
9898 } )
99+
100+ it ( 'should report close errors' , done => {
101+ gracefulFsStub . open = u ( ( pathIgnored , flagsIgnored , modeIgnored , callback ) => {
102+ if ( typeof modeIgnored === 'function' ) callback = modeIgnored
103+ process . nextTick ( ( ) => callback ( null , 42 ) )
104+ } )
105+
106+ const closeError = new Error ( 'close error' )
107+ gracefulFsStub . close = u ( ( fd , callback ) => {
108+ process . nextTick ( ( ) => callback ( closeError ) )
109+ } )
110+
111+ gracefulFsStub . futimes = u ( ( fd , atimeIgnored , mtimeIgnored , callback ) => {
112+ process . nextTick ( callback )
113+ } )
114+
115+ utimes . utimesMillis ( 'ignored' , 'ignored' , 'ignored' , err => {
116+ assert . strictEqual ( err , closeError )
117+ done ( )
118+ } )
119+ } )
120+
121+ it ( 'should throw futimes error even if close also errors' , done => {
122+ gracefulFsStub . open = u ( ( pathIgnored , flagsIgnored , modeIgnored , callback ) => {
123+ if ( typeof modeIgnored === 'function' ) callback = modeIgnored
124+ process . nextTick ( ( ) => callback ( null , 42 ) )
125+ } )
126+
127+ gracefulFsStub . close = u ( ( fd , callback ) => {
128+ process . nextTick ( ( ) => callback ( new Error ( 'close error' ) ) )
129+ } )
130+
131+ let testError
132+ gracefulFsStub . futimes = u ( ( fd , atimeIgnored , mtimeIgnored , callback ) => {
133+ process . nextTick ( ( ) => {
134+ testError = new Error ( 'A test error' )
135+ callback ( testError )
136+ } )
137+ } )
138+
139+ utimes . utimesMillis ( 'ignored' , 'ignored' , 'ignored' , err => {
140+ assert . strictEqual ( err , testError )
141+ done ( )
142+ } )
143+ } )
99144 } )
100145
101146 describe ( 'utimesMillisSync()' , ( ) => {
@@ -118,5 +163,33 @@ describe('utimes', () => {
118163 assert . throws ( ( ) => utimes . utimesMillisSync ( 'ignored' , 'ignored' , 'ignored' ) , testError )
119164 assert ( closeCalled )
120165 } )
166+
167+ it ( 'should report close errors' , ( ) => {
168+ gracefulFsStub . openSync = ( pathIgnored , flagsIgnored ) => 42
169+
170+ const closeError = new Error ( 'close error' )
171+ gracefulFsStub . closeSync = ( fd ) => {
172+ throw closeError
173+ }
174+
175+ gracefulFsStub . futimesSync = ( fd , atimeIgnored , mtimeIgnored ) => { }
176+
177+ assert . throws ( ( ) => utimes . utimesMillisSync ( 'ignored' , 'ignored' , 'ignored' ) , closeError )
178+ } )
179+
180+ it ( 'should throw futimes error even if close also errors' , ( ) => {
181+ gracefulFsStub . openSync = ( pathIgnored , flagsIgnored ) => 42
182+
183+ gracefulFsStub . closeSync = ( fd ) => {
184+ throw new Error ( 'close error' )
185+ }
186+
187+ const testError = new Error ( 'A test error' )
188+ gracefulFsStub . futimesSync = ( fd , atimeIgnored , mtimeIgnored ) => {
189+ throw testError
190+ }
191+
192+ assert . throws ( ( ) => utimes . utimesMillisSync ( 'ignored' , 'ignored' , 'ignored' ) , testError )
193+ } )
121194 } )
122195} )
0 commit comments