@@ -9,7 +9,8 @@ const ResultsPaneView = require('../lib/project/results-pane');
9
9
const etch = require ( 'etch' ) ;
10
10
const { beforeEach, it, fit, ffit, fffit, conditionPromise} = require ( './async-spec-helpers' )
11
11
12
- describe ( 'ProjectFindView' , ( ) => {
12
+ for ( const ripgrep of [ false , true ] ) {
13
+ describe ( `ProjectFindView (ripgrep=${ ripgrep } )` , ( ) => {
13
14
const { stoppedChangingDelay} = TextBuffer . prototype ;
14
15
let activationPromise , searchPromise , editor , editorElement , findView ,
15
16
projectFindView , workspaceElement ;
@@ -33,7 +34,14 @@ describe('ProjectFindView', () => {
33
34
return getExistingResultsPane ( ) . refs . resultsView ;
34
35
}
35
36
37
+ function waitForSearchResults ( ) {
38
+ return conditionPromise (
39
+ ( ) => projectFindView . refs . descriptionLabel . textContent . includes ( 'results found' )
40
+ )
41
+ }
42
+
36
43
beforeEach ( ( ) => {
44
+ atom . config . set ( 'find-and-replace.useRipgrep' , ripgrep )
37
45
workspaceElement = atom . views . getView ( atom . workspace ) ;
38
46
atom . config . set ( 'core.excludeVcsIgnoredPaths' , false ) ;
39
47
atom . project . setPaths ( [ path . join ( __dirname , 'fixtures' ) ] ) ;
@@ -278,6 +286,8 @@ describe('ProjectFindView', () => {
278
286
279
287
describe ( "when the find string contains an escaped char" , ( ) => {
280
288
beforeEach ( ( ) => {
289
+ jasmine . useRealClock ( )
290
+
281
291
let projectPath = temp . mkdirSync ( "atom" ) ;
282
292
fs . writeFileSync ( path . join ( projectPath , "tabs.txt" ) , "\t\n\\\t\n\\\\t" ) ;
283
293
atom . project . setPaths ( [ projectPath ] ) ;
@@ -396,6 +406,7 @@ describe('ProjectFindView', () => {
396
406
beforeEach ( ( ) => {
397
407
workspaceElement . style . height = '1000px' ;
398
408
atom . commands . dispatch ( editorElement , 'project-find:show' ) ;
409
+ jasmine . useRealClock ( )
399
410
} ) ;
400
411
401
412
it ( "splits when option is right" , async ( ) => {
@@ -451,6 +462,7 @@ describe('ProjectFindView', () => {
451
462
452
463
await etch . update ( resultsView1 ) ;
453
464
await etch . update ( resultsView2 ) ;
465
+ await waitForSearchResults ( ) ;
454
466
455
467
const resultCount = resultsPaneView1 . querySelectorAll ( '.match-row' ) . length ;
456
468
expect ( resultCount ) . toBeGreaterThan ( 0 ) ;
@@ -690,11 +702,16 @@ describe('ProjectFindView', () => {
690
702
} ) ;
691
703
692
704
describe ( "when project-find:confirm is triggered" , ( ) => {
705
+ beforeEach ( ( ) => {
706
+ jasmine . useRealClock ( )
707
+ } ) ;
708
+
693
709
it ( "displays the results and no errors" , async ( ) => {
694
710
projectFindView . findEditor . setText ( 'items' ) ;
695
711
atom . commands . dispatch ( projectFindView . element , 'project-find:confirm' ) ;
696
712
697
713
await searchPromise ;
714
+ await waitForSearchResults ( ) ;
698
715
699
716
const resultsView = getResultsView ( ) ;
700
717
await resultsView . heightInvalidationPromise
@@ -707,6 +724,7 @@ describe('ProjectFindView', () => {
707
724
describe ( "when core:confirm is triggered" , ( ) => {
708
725
beforeEach ( ( ) => {
709
726
atom . commands . dispatch ( workspaceElement , 'project-find:show' )
727
+ jasmine . useRealClock ( )
710
728
} ) ;
711
729
712
730
describe ( "when the there search field is empty" , ( ) => {
@@ -799,21 +817,29 @@ describe('ProjectFindView', () => {
799
817
expect ( listView . element . querySelectorAll ( ".path-row" ) [ 1 ] . parentElement ) . toHaveClass ( 'selected' ) ;
800
818
801
819
editor . setText ( 'there is one "items" in this file' ) ;
802
- advanceClock ( editor . getBuffer ( ) . stoppedChangingDelay ) ;
803
820
await etch . getScheduler ( ) . getNextUpdatePromise ( )
804
- expect ( resultsPaneView . refs . previewCount . textContent ) . toBe ( "8 results found in 2 files for items" ) ;
821
+ await searchPromise ;
822
+
823
+ await conditionPromise (
824
+ ( ) => resultsPaneView . refs . previewCount . textContent === "8 results found in 2 files for items"
825
+ )
826
+
805
827
expect ( listView . element . querySelectorAll ( ".path-row" ) [ 1 ] . parentElement ) . toHaveClass ( 'selected' ) ;
806
828
807
829
// Ensure the newly added item can be opened.
808
830
await resultsView . moveDown ( )
809
831
atom . commands . dispatch ( resultsView . element , 'core:confirm' ) ;
810
- await new Promise ( resolve => editor . onDidChangeSelectionRange ( resolve ) ) ;
811
- expect ( editor . getSelectedText ( ) ) . toBe ( "items" )
832
+ await waitForSearchResults ( ) ;
833
+ await conditionPromise (
834
+ ( ) => editor . getSelectedText ( ) === "items"
835
+ )
812
836
813
837
editor . setText ( 'no matches in this file' ) ;
814
- advanceClock ( editor . getBuffer ( ) . stoppedChangingDelay ) ;
815
- await etch . getScheduler ( ) . getNextUpdatePromise ( )
816
- expect ( resultsPaneView . refs . previewCount . textContent ) . toBe ( "7 results found in 1 file for items" ) ;
838
+ await waitForSearchResults ( ) ;
839
+
840
+ await conditionPromise (
841
+ ( ) => resultsPaneView . refs . previewCount . textContent === "7 results found in 1 file for items"
842
+ )
817
843
} ) ;
818
844
819
845
it ( "doesn't update the results list when a buffer outside the project changes" , async ( ) => {
@@ -826,7 +852,6 @@ describe('ProjectFindView', () => {
826
852
const resultsPaneView = getExistingResultsPane ( ) ;
827
853
828
854
await resultsView . heightInvalidationPromise
829
- console . log ( resultsView . refs . listView . element )
830
855
expect ( resultsView . refs . listView . element . querySelectorAll ( ".list-item" ) ) . toHaveLength ( 13 ) ;
831
856
expect ( resultsPaneView . refs . previewCount . textContent ) . toBe ( "13 results found in 2 files for items" ) ;
832
857
@@ -1087,6 +1112,7 @@ describe('ProjectFindView', () => {
1087
1112
} ) ;
1088
1113
1089
1114
it ( 'highlights the search results in the selected file' , async ( ) => {
1115
+ jasmine . useRealClock ( ) ;
1090
1116
// Process here is to
1091
1117
// * open samplejs
1092
1118
// * run a search that has sample js results
@@ -1100,6 +1126,7 @@ describe('ProjectFindView', () => {
1100
1126
projectFindView . findEditor . setText ( 'item' ) ;
1101
1127
atom . commands . dispatch ( projectFindView . element , 'core:confirm' ) ;
1102
1128
await searchPromise ;
1129
+ await waitForSearchResults ( ) ;
1103
1130
1104
1131
const resultsView = getResultsView ( ) ;
1105
1132
resultsView . scrollToBottom ( ) ; // To load ALL the results
@@ -1630,6 +1657,7 @@ describe('ProjectFindView', () => {
1630
1657
} ) ;
1631
1658
} ) ;
1632
1659
} ) ;
1660
+ }
1633
1661
1634
1662
function simulateResizeEvent ( element ) {
1635
1663
Array . from ( element . children ) . forEach ( ( child ) => {
0 commit comments