File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const { promisify } = require('util')
4
4
const mm = require ( 'minimatch' )
5
5
const Glob = require ( 'glob' ) . Glob
6
6
const fs = require ( 'graceful-fs' )
7
- fs . statAsync = promisify ( fs . stat )
7
+ const statAsync = promisify ( fs . stat . bind ( fs ) )
8
8
const pathLib = require ( 'path' )
9
9
const _ = require ( 'lodash' )
10
10
@@ -189,7 +189,7 @@ class FileList {
189
189
const file = new File ( path )
190
190
this . _getFilesByPattern ( pattern . pattern ) . push ( file )
191
191
192
- const [ stat ] = await Promise . all ( [ fs . statAsync ( path ) , this . _refreshing ] )
192
+ const [ stat ] = await Promise . all ( [ statAsync ( path ) , this . _refreshing ] )
193
193
file . mtime = stat . mtime
194
194
await this . _preprocess ( file )
195
195
@@ -207,7 +207,7 @@ class FileList {
207
207
return this . files
208
208
}
209
209
210
- const [ stat ] = await Promise . all ( [ fs . statAsync ( path ) , this . _refreshing ] )
210
+ const [ stat ] = await Promise . all ( [ statAsync ( path ) , this . _refreshing ] )
211
211
if ( force || stat . mtime > file . mtime ) {
212
212
file . mtime = stat . mtime
213
213
await this . _preprocess ( file )
Original file line number Diff line number Diff line change @@ -442,6 +442,10 @@ describe('FileList', () => {
442
442
clock = sinon . useFakeTimers ( )
443
443
// This hack is needed to ensure lodash is using the fake timers
444
444
// from sinon
445
+
446
+ // fs.stat needs to be spied before file-list is required
447
+ sinon . spy ( mockFs , 'stat' )
448
+
445
449
List = proxyquire ( '../../lib/file-list' , {
446
450
lodash : _ . runInContext ( ) ,
447
451
helper : helper ,
@@ -455,6 +459,7 @@ describe('FileList', () => {
455
459
456
460
afterEach ( ( ) => {
457
461
clock . restore ( )
462
+ mockFs . stat . restore ( )
458
463
} )
459
464
460
465
it ( 'does not add excluded files' , ( ) => {
@@ -511,14 +516,13 @@ describe('FileList', () => {
511
516
512
517
return list . refresh ( ) . then ( ( ) => {
513
518
preprocess . resetHistory ( )
514
- sinon . spy ( mockFs , 'statAsync' )
515
519
516
520
return Promise . all ( [
517
521
list . addFile ( '/some/d.js' ) ,
518
522
list . addFile ( '/some/d.js' )
519
523
] ) . then ( ( ) => {
520
524
expect ( preprocess ) . to . have . been . calledOnce
521
- expect ( mockFs . statAsync ) . to . have . been . calledOnce
525
+ expect ( mockFs . stat ) . to . have . been . calledOnce
522
526
} )
523
527
} )
524
528
} )
You can’t perform that action at this time.
0 commit comments