11defmodule Lexical.RemoteControl.Search.IndexerTest do
22 alias Lexical.Project
3+ alias Lexical.RemoteControl.Dispatch
34 alias Lexical.RemoteControl.Search.Indexer
45 alias Lexical.RemoteControl.Search.Indexer.Entry
56
@@ -24,7 +25,7 @@ defmodule Lexical.RemoteControl.Search.IndexerTest do
2425
2526 setup do
2627 project = project ( )
27- start_supervised ( Lexical.RemoteControl. Dispatch)
28+ start_supervised ( Dispatch )
2829 { :ok , project: project }
2930 end
3031
@@ -46,12 +47,8 @@ defmodule Lexical.RemoteControl.Search.IndexerTest do
4647
4748 @ ephemeral_file_name "ephemeral.ex"
4849
49- def with_an_ephemeral_file ( % { project: project } ) do
50+ def with_an_ephemeral_file ( % { project: project } , file_contents ) do
5051 file_path = Path . join ( [ Project . root_path ( project ) , "lib" , @ ephemeral_file_name ] )
51- file_contents = ~s[
52- defmodule Ephemeral do
53- end
54- ]
5552 File . write! ( file_path , file_contents )
5653
5754 on_exit ( fn ->
@@ -61,6 +58,14 @@ defmodule Lexical.RemoteControl.Search.IndexerTest do
6158 { :ok , file_path: file_path }
6259 end
6360
61+ def with_a_file_with_a_module ( context ) do
62+ file_contents = ~s[
63+ defmodule Ephemeral do
64+ end
65+ ]
66+ with_an_ephemeral_file ( context , file_contents )
67+ end
68+
6469 def with_an_existing_index ( % { project: project } ) do
6570 { :ok , entry_stream } = Indexer . create_index ( project )
6671 entries = Enum . to_list ( entry_stream )
@@ -69,7 +74,7 @@ defmodule Lexical.RemoteControl.Search.IndexerTest do
6974 end
7075
7176 describe "update_index/2 encounters a new file" do
72- setup [ :with_an_existing_index , :with_an_ephemeral_file ]
77+ setup [ :with_an_existing_index , :with_a_file_with_a_module ]
7378
7479 test "the ephemeral file is not previously present in the index" , % { entries: entries } do
7580 refute Enum . any? ( entries , fn entry -> Path . basename ( entry . path ) == @ ephemeral_file_name end )
@@ -83,8 +88,31 @@ defmodule Lexical.RemoteControl.Search.IndexerTest do
8388 end
8489 end
8590
91+ def with_an_ephemeral_empty_file ( context ) do
92+ with_an_ephemeral_file ( context , "" )
93+ end
94+
95+ describe "update_index/2 encounters a zero-length file" do
96+ setup [ :with_an_existing_index , :with_an_ephemeral_empty_file ]
97+
98+ test "and does nothing" , % { project: project } do
99+ { :ok , entry_stream , [ ] } = Indexer . update_index ( project , FakeBackend )
100+ assert [ ] = Enum . to_list ( entry_stream )
101+ end
102+
103+ test "there is no progress" , % { project: project } do
104+ # this ensures we don't emit progress with a total byte size of 0, which will
105+ # cause an ArithmeticError
106+
107+ Dispatch . register_listener ( self ( ) , :all )
108+ { :ok , entry_stream , [ ] } = Indexer . update_index ( project , FakeBackend )
109+ assert [ ] = Enum . to_list ( entry_stream )
110+ refute_receive _
111+ end
112+ end
113+
86114 describe "update_index/2" do
87- setup [ :with_an_ephemeral_file , :with_an_existing_index ]
115+ setup [ :with_a_file_with_a_module , :with_an_existing_index ]
88116
89117 test "sees the ephemeral file" , % { entries: entries } do
90118 assert Enum . any? ( entries , fn entry -> Path . basename ( entry . path ) == @ ephemeral_file_name end )
0 commit comments