Class: Ask::Ruby::Harness::Tools::RunTests
- Inherits:
-
Ask::Ruby::Harness::Tool
- Object
- Tool
- Ask::Ruby::Harness::Tool
- Ask::Ruby::Harness::Tools::RunTests
- Defined in:
- lib/ask/ruby/harness/tools/run_tests.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
300- ARTIFACT_DIR =
%w[tmp test .ask].freeze
Instance Method Summary collapse
Methods inherited from Ask::Ruby::Harness::Tool
#app_root, #call, session_id, session_id=
Instance Method Details
#execute(file: nil, name: nil, failed_only: false, timeout: DEFAULT_TIMEOUT) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ask/ruby/harness/tools/run_tests.rb', line 25 def execute(file: nil, name: nil, failed_only: false, timeout: DEFAULT_TIMEOUT) files = split_files(file) # Monorepo support: a file inside a subproject (a dir with its # own Gemfile/Rakefile) runs that project's suite. run_root = resolve_run_root(files) files = files.map { |f| rel_to_run_root(f, run_root) } runner = detect_runner(run_root) # rake test only takes files (TEST env); expand directory args to # their *_test.rb files. Rails and rspec expand dirs natively. if runner == :minitest = (files, run_root) return unless .is_a?(Array) files = end failed_tests = failed_only ? load_failed_tests(run_root) : nil if failed_only && failed_tests.empty? return Ask::Result.failure("No failed tests from the previous run to rerun.") end artifact_dir = run_root.join(*ARTIFACT_DIR).tap(&:mkpath) log_path = artifact_dir.join("last-test.log") json_path = artifact_dir.join("last-test.json") status_path = artifact_dir.join("last-failures.json") # A child that produces no JSON must not be masked by a previous # run's stale file — parse_results only looks at this path. json_path.delete if json_path.exist? command, env = build_command(runner, files, name, failed_tests, json_path) outcome = run(command, env, log_path, timeout, run_root) results = parse_results(runner, json_path) unless results # A killed run can't produce results — report it structurally # instead of failing, so the agent still gets the artifact path. return Ask::Result.ok(data: timed_out_report(runner, command, env, outcome, status_path, log_path, run_root)) if outcome[:timed_out] return Ask::Result.failure( "Test run finished without machine-readable results (#{runner}); " \ "full output at #{rel(log_path, run_root)}" ) end report = build_report(runner, command, env, outcome, results, status_path, log_path, run_root) Ask::Result.ok(data: report) end |