Skip to content

Commit

Permalink
Add "a" watch keypress command to run --all tests (#16)
Browse files Browse the repository at this point in the history
Now there are 2 ways to run the entire test suite via interactive watch
commands:

- ENTER runs all tests, excluding slow ones
- "a" runs all tests, slow tests included (equivalent to `mt --all`)
  • Loading branch information
mattbrictson authored Feb 25, 2024
1 parent 7cef63d commit b6480c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lib/mighty_test/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(console: Console.new, extra_args: [], file_system: FileSystem.new
@system_proc = system_proc
end

def run(iterations: :indefinitely) # rubocop:disable Metrics/MethodLength
def run(iterations: :indefinitely) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
start_file_system_listener
start_keypress_listener
puts WATCHING_FOR_CHANGES
Expand All @@ -23,6 +23,8 @@ def run(iterations: :indefinitely) # rubocop:disable Metrics/MethodLength
run_matching_test_files(paths)
in [:keypress, "\r" | "\n"]
run_all_tests
in [:keypress, "a"]
run_all_tests(flags: ["--all"])
in [:keypress, "d"]
run_matching_test_files_from_git_diff
in [:keypress, "q"]
Expand All @@ -41,11 +43,11 @@ def run(iterations: :indefinitely) # rubocop:disable Metrics/MethodLength

attr_reader :console, :extra_args, :file_system, :file_system_listener, :keypress_listener, :system_proc

def run_all_tests
def run_all_tests(flags: [])
console.clear
puts "Running all tests..."
puts flags.any? ? "Running tests with #{flags.join(' ')}..." : "Running tests..."
puts
mt
mt(flags:)
end

def run_matching_test_files(paths)
Expand All @@ -67,8 +69,8 @@ def run_matching_test_files_from_git_diff
puts WATCHING_FOR_CHANGES
end

def mt(*test_paths)
command = ["mt", *extra_args]
def mt(*test_paths, flags: [])
command = ["mt", *extra_args, *flags]
command.append("--", *test_paths.flatten) if test_paths.any?

success = system_proc.call(*command)
Expand Down
17 changes: 16 additions & 1 deletion test/mighty_test/watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,27 @@ def test_watcher_runs_all_tests_when_enter_key_is_pressed
stdout, = run_watcher(stdin: "\rq", in: fixtures_path.join("example_project"))

assert_includes(stdout, <<~EXPECTED)
Running all tests...
Running tests...
[SYSTEM] mt
EXPECTED
end

def test_watcher_runs_all_tests_with_all_flag_when_a_key_is_pressed
system_proc do |*args|
puts "[SYSTEM] #{args.join(' ')}"
true
end

stdout, = run_watcher(stdin: "aq", in: fixtures_path.join("example_project"))

assert_includes(stdout, <<~EXPECTED)
Running tests with --all...
[SYSTEM] mt --all
EXPECTED
end

def test_watcher_runs_new_and_changed_files_according_to_git_when_d_key_is_pressed
system_proc do |*args|
puts "[SYSTEM] #{args.join(' ')}"
Expand Down

0 comments on commit b6480c7

Please sign in to comment.