@@ -182,6 +182,52 @@ describe('File', function() {
182182 ] ) ;
183183 }
184184 } ) ;
185+
186+ it ( 'appends path to history if both exist and different from last' , function ( done ) {
187+ var p = path . normalize ( '/test/baz/test.coffee' ) ;
188+ var history = [
189+ path . normalize ( '/test/bar/test.coffee' ) ,
190+ path . normalize ( '/test/foo/test.coffee' ) ,
191+ ] ;
192+ var file = new File ( { path : p , history : history } ) ;
193+
194+ var expectedHistory = history . concat ( p ) ;
195+
196+ file . path . should . equal ( path . normalize ( '/test/baz/test.coffee' ) ) ;
197+ file . history . should . eql ( expectedHistory ) ;
198+ done ( ) ;
199+ } ) ;
200+
201+ it ( 'does not append path to history if both exist and same as last' , function ( done ) {
202+ var history = [
203+ path . normalize ( '/test/bar/test.coffee' ) ,
204+ path . normalize ( '/test/foo/test.coffee' ) ,
205+ path . normalize ( '/test/baz/test.coffee' ) ,
206+ ] ;
207+ var file = new File ( { path : history [ history . length - 1 ] , history : history } ) ;
208+
209+ file . path . should . equal ( path . normalize ( '/test/baz/test.coffee' ) ) ;
210+ file . history . should . eql ( history ) ;
211+ done ( ) ;
212+ } ) ;
213+
214+ it ( 'does not mutate history array passed in' , function ( done ) {
215+ var p = path . normalize ( '/test/baz/test.coffee' ) ;
216+ var history = [
217+ path . normalize ( '/test/bar/test.coffee' ) ,
218+ path . normalize ( '/test/foo/test.coffee' ) ,
219+ ] ;
220+ var historyCopy = Array . prototype . slice . call ( history ) ;
221+ var file = new File ( { path : p , history : history } ) ;
222+
223+ var expectedHistory = history . concat ( p ) ;
224+
225+ file . path . should . equal ( path . normalize ( '/test/baz/test.coffee' ) ) ;
226+ file . history . should . eql ( expectedHistory ) ;
227+ history . should . eql ( historyCopy ) ;
228+ done ( ) ;
229+ } ) ;
230+
185231 } ) ;
186232
187233 describe ( 'isBuffer()' , function ( ) {
0 commit comments