@@ -21,6 +21,14 @@ function getFixturePath (subPath) {
21
21
subPath
22
22
) ;
23
23
}
24
+ function getGlobPath ( subPath ) {
25
+ return upath . join (
26
+ __dirname ,
27
+ 'test-fixtures' ,
28
+ subdir && subdir . toString ( ) || '' ,
29
+ subPath
30
+ ) ;
31
+ }
24
32
25
33
var watcher ,
26
34
watcher2 ,
@@ -516,10 +524,10 @@ function runTests(baseopts) {
516
524
before ( closeWatchers ) ;
517
525
it ( 'should correctly watch and emit based on glob input' , function ( done ) {
518
526
var spy = sinon . spy ( ) ;
519
- var testPath = getFixturePath ( '*a*.txt' ) ;
527
+ var watchPath = getGlobPath ( '*a*.txt' ) ;
520
528
var addPath = getFixturePath ( 'add.txt' ) ;
521
529
var changePath = getFixturePath ( 'change.txt' ) ;
522
- watcher = chokidar . watch ( testPath , options )
530
+ watcher = chokidar . watch ( watchPath , options )
523
531
. on ( 'all' , spy )
524
532
. on ( 'ready' , function ( ) {
525
533
spy . should . have . been . calledWith ( 'add' , changePath ) ;
@@ -538,10 +546,10 @@ function runTests(baseopts) {
538
546
} ) ;
539
547
it ( 'should respect negated glob patterns' , function ( done ) {
540
548
var spy = sinon . spy ( ) ;
541
- var testPath = getFixturePath ( '*' ) ;
542
- var negatedPath = '!' + getFixturePath ( '*a*.txt' ) ;
549
+ var watchPath = getGlobPath ( '*' ) ;
550
+ var negatedWatchPath = '!' + getGlobPath ( '*a*.txt' ) ;
543
551
var unlinkPath = getFixturePath ( 'unlink.txt' ) ;
544
- watcher = chokidar . watch ( [ testPath , negatedPath ] , options )
552
+ watcher = chokidar . watch ( [ watchPath , negatedWatchPath ] , options )
545
553
. on ( 'all' , spy )
546
554
. on ( 'ready' , function ( ) {
547
555
spy . should . have . been . calledOnce ;
@@ -556,7 +564,7 @@ function runTests(baseopts) {
556
564
} ) ;
557
565
it ( 'should traverse subdirs to match globstar patterns' , function ( done ) {
558
566
var spy = sinon . spy ( ) ;
559
- var watchPath = getFixturePath ( '../../test-*/' + subdir + '/**/a*.txt' ) ;
567
+ var watchPath = getGlobPath ( '../../test-*/' + subdir + '/**/a*.txt' ) ;
560
568
fs . mkdirSync ( getFixturePath ( 'subdir' ) , 0x1ed ) ;
561
569
fs . mkdirSync ( getFixturePath ( 'subdir/subsub' ) , 0x1ed ) ;
562
570
fs . writeFileSync ( getFixturePath ( 'subdir/a.txt' ) , 'b' ) ;
@@ -587,12 +595,12 @@ function runTests(baseopts) {
587
595
} ) ;
588
596
it ( 'should resolve relative paths with glob patterns' , function ( done ) {
589
597
var spy = sinon . spy ( ) ;
590
- var testPath = 'test-*/' + subdir + '/*a*.txt' ;
598
+ var watchPath = 'test-*/' + subdir + '/*a*.txt' ;
591
599
// getFixturePath() returns absolute paths, so use sysPath.join() instead
592
600
var addPath = sysPath . join ( 'test-fixtures' , subdir . toString ( ) , 'add.txt' ) ;
593
601
var changePath = sysPath . join ( 'test-fixtures' , subdir . toString ( ) , 'change.txt' ) ;
594
602
var unlinkPath = sysPath . join ( 'test-fixtures' , subdir . toString ( ) , 'unlink.txt' ) ;
595
- watcher = chokidar . watch ( testPath , options )
603
+ watcher = chokidar . watch ( watchPath , options )
596
604
. on ( 'all' , spy )
597
605
. on ( 'ready' , function ( ) {
598
606
spy . should . have . been . calledWith ( 'add' , changePath ) ;
@@ -615,7 +623,7 @@ function runTests(baseopts) {
615
623
var changePath = getFixturePath ( 'change.txt' ) ;
616
624
var unlinkPath = getFixturePath ( 'unlink.txt' ) ;
617
625
var addPath = getFixturePath ( 'add.txt' ) ;
618
- var watchPaths = [ getFixturePath ( 'change*' ) , getFixturePath ( 'unlink*' ) ] ;
626
+ var watchPaths = [ getGlobPath ( 'change*' ) , getGlobPath ( 'unlink*' ) ] ;
619
627
watcher = chokidar . watch ( watchPaths , options )
620
628
. on ( 'all' , spy )
621
629
. on ( 'ready' , function ( ) {
@@ -639,7 +647,7 @@ function runTests(baseopts) {
639
647
it ( 'should correctly handle intersecting glob patterns' , function ( done ) {
640
648
var spy = sinon . spy ( ) ;
641
649
var changePath = getFixturePath ( 'change.txt' ) ;
642
- var watchPaths = [ getFixturePath ( 'cha*' ) , getFixturePath ( '*nge.*' ) ] ;
650
+ var watchPaths = [ getGlobPath ( 'cha*' ) , getGlobPath ( '*nge.*' ) ] ;
643
651
watcher = chokidar . watch ( watchPaths , options )
644
652
. on ( 'all' , spy )
645
653
. on ( 'ready' , function ( ) {
@@ -674,10 +682,11 @@ function runTests(baseopts) {
674
682
var spy = sinon . spy ( ) ;
675
683
var filePath = getFixturePath ( 'nota[glob]/a.txt' ) ;
676
684
var watchPath = getFixturePath ( 'nota[glob]' ) ;
685
+ var testDir = getFixturePath ( 'nota[glob]' ) ;
677
686
var matchingDir = getFixturePath ( 'notag' ) ;
678
687
var matchingFile = getFixturePath ( 'notag/b.txt' ) ;
679
688
var matchingFile2 = getFixturePath ( 'notal' ) ;
680
- fs . mkdirSync ( watchPath , 0x1ed ) ;
689
+ fs . mkdirSync ( testDir , 0x1ed ) ;
681
690
fs . writeFileSync ( filePath , 'b' ) ;
682
691
fs . mkdirSync ( matchingDir , 0x1ed ) ;
683
692
fs . writeFileSync ( matchingFile , 'c' ) ;
@@ -700,6 +709,7 @@ function runTests(baseopts) {
700
709
options . disableGlobbing = true ;
701
710
var spy = sinon . spy ( ) ;
702
711
var filePath = getFixturePath ( 'nota[glob]' ) ;
712
+ // This isn't using getGlobPath because it isn't treated as a glob
703
713
var watchPath = getFixturePath ( 'nota[glob]' ) ;
704
714
var matchingDir = getFixturePath ( 'notag' ) ;
705
715
var matchingFile = getFixturePath ( 'notag/a.txt' ) ;
@@ -725,7 +735,7 @@ function runTests(baseopts) {
725
735
it ( 'should not prematurely filter dirs against complex globstar patterns' , function ( done ) {
726
736
var spy = sinon . spy ( ) ;
727
737
var deepFile = getFixturePath ( 'subdir/subsub/subsubsub/a.txt' ) ;
728
- var watchPath = getFixturePath ( '../../test-*/' + subdir + '/**/subsubsub/*.txt' ) ;
738
+ var watchPath = getGlobPath ( '../../test-*/' + subdir + '/**/subsubsub/*.txt' ) ;
729
739
fs . mkdirSync ( getFixturePath ( 'subdir' ) , 0x1ed ) ;
730
740
fs . mkdirSync ( getFixturePath ( 'subdir/subsub' ) , 0x1ed ) ;
731
741
fs . mkdirSync ( getFixturePath ( 'subdir/subsub/subsubsub' ) , 0x1ed ) ;
@@ -744,7 +754,7 @@ function runTests(baseopts) {
744
754
it ( 'should emit matching dir events' , function ( done ) {
745
755
var spy = sinon . spy ( ) ;
746
756
// test with and without globstar matches
747
- var watchPaths = [ getFixturePath ( '*' ) , getFixturePath ( 'subdir/subsub/**/*' ) ] ;
757
+ var watchPaths = [ getGlobPath ( '*' ) , getGlobPath ( 'subdir/subsub/**/*' ) ] ;
748
758
var deepDir = getFixturePath ( 'subdir/subsub/subsubsub' ) ;
749
759
var deepFile = sysPath . join ( deepDir , 'a.txt' ) ;
750
760
fs . mkdirSync ( getFixturePath ( 'subdir' ) , 0x1ed ) ;
@@ -770,7 +780,7 @@ function runTests(baseopts) {
770
780
} ) ;
771
781
it ( 'should correctly handle glob with braces' , function ( done ) {
772
782
var spy = sinon . spy ( ) ;
773
- var watchPath = upath . normalizeSafe ( getFixturePath ( '{subdir/*,subdir1/subsub1}/subsubsub/*.txt' ) ) ;
783
+ var watchPath = upath . normalizeSafe ( getGlobPath ( '{subdir/*,subdir1/subsub1}/subsubsub/*.txt' ) ) ;
774
784
var deepFileA = getFixturePath ( 'subdir/subsub/subsubsub/a.txt' ) ;
775
785
var deepFileB = getFixturePath ( 'subdir1/subsub1/subsubsub/a.txt' ) ;
776
786
fs . mkdirSync ( getFixturePath ( 'subdir' ) , 0x1ed ) ;
@@ -966,8 +976,8 @@ function runTests(baseopts) {
966
976
var dirSpy = sinon . spy ( function dirSpy ( ) { } ) ;
967
977
var addSpy = sinon . spy ( function addSpy ( ) { } ) ;
968
978
// test with relative path to ensure proper resolution
969
- var watchDir = sysPath . relative ( process . cwd ( ) , linkedDir ) ;
970
- watcher = chokidar . watch ( sysPath . join ( watchDir , '**/*' ) , options )
979
+ var watchDir = upath . relative ( process . cwd ( ) , linkedDir ) ;
980
+ watcher = chokidar . watch ( upath . join ( watchDir , '**/*' ) , options )
971
981
. on ( 'addDir' , dirSpy )
972
982
. on ( 'add' , addSpy )
973
983
. on ( 'ready' , function ( ) {
@@ -1413,7 +1423,7 @@ function runTests(baseopts) {
1413
1423
var options2 = { } ;
1414
1424
Object . keys ( options ) . forEach ( function ( key ) { options2 [ key ] = options [ key ] } ) ;
1415
1425
options2 . cwd = getFixturePath ( 'subdir' ) ;
1416
- watcher = chokidar . watch ( getFixturePath ( '**' ) , options )
1426
+ watcher = chokidar . watch ( getGlobPath ( '**' ) , options )
1417
1427
. on ( 'all' , spy1 )
1418
1428
. on ( 'ready' , w ( function ( ) {
1419
1429
watcher2 = chokidar . watch ( fixturesPath , options2 )
@@ -1754,8 +1764,8 @@ function runTests(baseopts) {
1754
1764
. on ( 'all' , spy )
1755
1765
. on ( 'ready' , w ( function ( ) {
1756
1766
// test with both relative and absolute paths
1757
- var subdirRel = sysPath . relative ( process . cwd ( ) , getFixturePath ( 'subdir' ) ) ;
1758
- watcher . unwatch ( [ subdirRel , getFixturePath ( 'unl*' ) ] ) ;
1767
+ var subdirRel = upath . relative ( process . cwd ( ) , getFixturePath ( 'subdir' ) ) ;
1768
+ watcher . unwatch ( [ subdirRel , getGlobPath ( 'unl*' ) ] ) ;
1759
1769
w ( function ( ) {
1760
1770
fs . unlink ( getFixturePath ( 'unlink.txt' ) , simpleCb ) ;
1761
1771
fs . writeFile ( getFixturePath ( 'subdir/add.txt' ) , Date . now ( ) , simpleCb ) ;
0 commit comments