Skip to content

Commit

Permalink
Add filter and list tests options
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Sep 13, 2024
1 parent 836c41c commit 1330bc9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion anyt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "minitest", "~> 5.10"
spec.add_dependency "minitest-reporters", "~> 1.1.0"
spec.add_dependency "anycable-rails", "> 1.0.99", "< 2.0"
spec.add_dependency "redis", "~> 4.0"
spec.add_dependency "redis", ">= 4.0"
spec.add_dependency "childprocess", "~> 3.0"

spec.add_development_dependency "bundler", "~> 2"
Expand Down
15 changes: 15 additions & 0 deletions lib/anyt/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class << self
def run(args = ARGV)
parse_options!(args)

if Anyt.config.list_tests
Tests.load_tests
Tests.list
return 0
end

ActionCable.server.config.logger = Rails.logger = AnyCable.logger

result = 1
Expand Down Expand Up @@ -128,6 +134,11 @@ def parse_options!(args)
configure_rails_command!
end

cli.on("-l", "--list", TrueClass, "List test scenarios") do
Anyt.config.list_tests = true
@skip_rpc = true
end

cli.on("--self-check", "Run tests again Action Cable itself") do
@skip_rpc = true

Expand All @@ -142,6 +153,10 @@ def parse_options!(args)
Anyt.config.except_tests = except_tests
end

cli.on("-e filter", "Run only tests matching the descripton") do |filter_tests|
Anyt.config.filter_tests = filter_tests
end

cli.on("--wait-command=TIMEOUT", Integer,
"Number of seconds to wait for WS server initialization") do |timeout|
Anyt.config.wait_command = timeout
Expand Down
10 changes: 10 additions & 0 deletions lib/anyt/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

require "anyway"

Anyway::Rails.disable_postponed_load_warning = true

module Anyt
# Anyt configuration
class Config < Anyway::Config
attr_config :command,
:only_tests,
:except_tests,
:filter_tests,
:list_tests,
:tests_relative_path,
remote_control_port: 8919,
use_action_cable: false,
Expand Down Expand Up @@ -37,5 +41,11 @@ def tests_filter
(except_rxp.nil? || !except_rxp.match?(path))
end
end

def example_filter
return unless filter_tests

/#{filter_tests}/i
end
end
end
6 changes: 4 additions & 2 deletions lib/anyt/dummy/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def subscribed
end

def echo(data)
if ECHO_DELAY > 0
sleep ECHO_DELAY
puts "ECHO: #{data.inspect}" if data["verbose"]
delay = data.fetch("delay", ECHO_DELAY).to_f
if delay > 0
sleep delay
end
transmit data
end
Expand Down
3 changes: 3 additions & 0 deletions lib/anyt/ext/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ module Minitest::Spec::DSL
# Simplified version of `it` which doesn't care
# about unique method names
def scenario(desc, &block)
full_desc = "#{name.gsub(/\n/, " ").strip} #{desc.gsub(/\n/, " ").strip}"
return if Anyt.config.example_filter && !Anyt.config.example_filter.match?(full_desc)

block ||= proc { skip "(no tests defined)" }

define_method "test_ #{desc}", &block
Expand Down
20 changes: 20 additions & 0 deletions lib/anyt/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,29 @@ def run
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

AnyCable.logger.debug "Run tests against: #{Anyt.config.target_url}"

Minitest.run
end

def list
printer = Object.new
printer.extend include ANSI::Code

Minitest::Runnable.runnables.each do |runnable|
def runnable.test_order
:sorted
end
next unless runnable.runnable_methods.any?

$stdout.puts(runnable.name)

runnable.runnable_methods.each do |method|
test_name = method.gsub(/^test_/, "").strip
$stdout.puts(printer.magenta { " #{test_name}" })
end
end
end

# Load tests code (filtered if present)
#
# NOTE: We should run this before launching RPC server
Expand Down

0 comments on commit 1330bc9

Please sign in to comment.