Class: SimpleCov::CLI::Watch::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/cli/watch/session.rb

Overview

One watch session: accept report connections in the background, poll the tracked set for changes, re-run tests on save (selecting over the recorded test map when the report carries one), and push a reload to every open tab when the report regenerates.

Constant Summary collapse

MERGE_WINDOW =

The merge window the child runs get through SIMPLECOV_MERGE_TIMEOUT: a day, so subset re-runs keep merging into a whole report across a long session instead of eroding it after the default ten minutes.

"86400"
TOTALS_KEYS =
{"line" => "lines", "branch" => "branches", "method" => "methods"}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(command:, dir:, interval:, stdout:, stderr:) ⇒ Session

Returns a new instance of Session.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simplecov/cli/watch/session.rb', line 18

def initialize(command:, dir:, interval:, stdout:, stderr:)
  @command = command
  @dir = dir
  @interval = interval
  @stderr = stderr
  @root = Dir.pwd
  @narrator = Narrator.new(stdout, @root)
  @live = LiveReport.new(dir)
  @poller = Poller.new
  @document = {} #: Hash[String, untyped]
end

Instance Method Details

#poll_foreverObject



42
43
44
45
46
47
# File 'lib/simplecov/cli/watch/session.rb', line 42

def poll_forever
  loop do
    sleep(@interval)
    step
  end
end

#run(server) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simplecov/cli/watch/session.rb', line 30

def run(server)
  accept_loop(server)
  run_tests(nil) unless File.exist?(json_path)
  return 1 unless refresh

  @narrator.banner(server, @poller.size)
  poll_forever
rescue Interrupt
  @narrator.stopping
  0
end

#stepObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/simplecov/cli/watch/session.rb', line 49

def step
  changed = settled_changes
  return if changed.empty?

  plan = plan_for(changed)
  @narrator.change(changed, plan)
  return unless plan.fetch(:run)

  before = total_percent
  run_tests(plan.fetch(:tests))
  return @narrator.failed_refresh unless refresh

  @live.broadcast
  @narrator.result(before, total_percent)
end