@@ -1386,8 +1386,10 @@ describe('volume', () => {
1386
1386
try {
1387
1387
vol . writeFileSync ( '/tmp/foo-dir/foo.js' , writtenContent ) ;
1388
1388
1389
- expect ( mockCallback ) . toBeCalledTimes ( 1 ) ;
1390
- expect ( mockCallback ) . toBeCalledWith ( 'rename' , 'foo.js' ) ;
1389
+ expect ( mockCallback ) . toBeCalledTimes ( 3 ) ;
1390
+ expect ( mockCallback ) . nthCalledWith ( 1 , 'rename' , 'foo.js' ) ;
1391
+ expect ( mockCallback ) . nthCalledWith ( 2 , 'change' , 'foo.js' ) ;
1392
+ expect ( mockCallback ) . nthCalledWith ( 3 , 'change' , 'foo.js' ) ;
1391
1393
} finally {
1392
1394
watcher . close ( ) ;
1393
1395
}
@@ -1442,13 +1444,15 @@ describe('volume', () => {
1442
1444
1443
1445
setTimeout ( ( ) => {
1444
1446
watcher . close ( ) ;
1445
- expect ( listener ) . toBeCalledTimes ( 6 ) ;
1447
+ expect ( listener ) . toBeCalledTimes ( 8 ) ;
1446
1448
expect ( listener ) . nthCalledWith ( 1 , 'change' , 'lol.txt' ) ;
1447
1449
expect ( listener ) . nthCalledWith ( 2 , 'change' , 'lol.txt' ) ;
1448
1450
expect ( listener ) . nthCalledWith ( 3 , 'rename' , 'test/lol.txt' ) ;
1449
- expect ( listener ) . nthCalledWith ( 4 , 'rename' , 'lol.txt' ) ;
1450
- expect ( listener ) . nthCalledWith ( 5 , 'rename' , 'test/lol.txt' ) ;
1451
- expect ( listener ) . nthCalledWith ( 6 , 'rename' , 'test/foo' ) ;
1451
+ expect ( listener ) . nthCalledWith ( 4 , 'change' , 'test/lol.txt' ) ;
1452
+ expect ( listener ) . nthCalledWith ( 5 , 'change' , 'test/lol.txt' ) ;
1453
+ expect ( listener ) . nthCalledWith ( 6 , 'rename' , 'lol.txt' ) ;
1454
+ expect ( listener ) . nthCalledWith ( 7 , 'rename' , 'test/lol.txt' ) ;
1455
+ expect ( listener ) . nthCalledWith ( 8 , 'rename' , 'test/foo' ) ;
1452
1456
done ( ) ;
1453
1457
} , 10 ) ;
1454
1458
} ) ;
@@ -1475,6 +1479,28 @@ describe('volume', () => {
1475
1479
} , 10 ) ;
1476
1480
} ) ;
1477
1481
} ) ;
1482
+ it ( 'Calls listener for file created immediately after directory creation' , done => {
1483
+ const vol = new Volume ( ) ;
1484
+ vol . mkdirSync ( '/watched' , { recursive : true } ) ;
1485
+
1486
+ const listener = jest . fn ( ) ;
1487
+ const watcher = vol . watch ( '/watched' , { recursive : true } , listener ) ;
1488
+
1489
+ // Create directory and immediately create file inside it
1490
+ vol . mkdirSync ( '/watched/new_dir' , { recursive : true } ) ;
1491
+ vol . writeFileSync ( '/watched/new_dir/new_file' , 'content' ) ;
1492
+
1493
+ setTimeout ( ( ) => {
1494
+ watcher . close ( ) ;
1495
+
1496
+ // Should have at least 3 events: directory creation, file creation, file change
1497
+ expect ( listener ) . toHaveBeenCalledWith ( 'rename' , 'new_dir' ) ;
1498
+ expect ( listener ) . toHaveBeenCalledWith ( 'rename' , 'new_dir/new_file' ) ;
1499
+ expect ( listener ) . toHaveBeenCalledWith ( 'change' , 'new_dir/new_file' ) ;
1500
+
1501
+ done ( ) ;
1502
+ } , 10 ) ;
1503
+ } ) ;
1478
1504
} ) ;
1479
1505
describe ( '.watchFile(path[, options], listener)' , ( ) => {
1480
1506
it ( 'Calls listener on .writeFile' , done => {
0 commit comments