diff --git a/Readme.md b/Readme.md index 005a9e89..19cefe03 100644 --- a/Readme.md +++ b/Readme.md @@ -129,7 +129,7 @@ Test groups will often run for different times, making the full test run as slow **Step 1**: Use these loggers (see below) to record test runtime -**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log ` if you picked a location different from below) +**Step 2**: The next test run will use the recorded test runtimes (use `--runtime-log ` if you wrote to a location different from default) **Step 3**: Automate upload/download of test runtime from your CI system [example](https://github.com/grosser/parallel_rails_example/blob/master/.github/workflows/test.yml) (chunks need to be combined, an alternative is [amend](https://github.com/grosser/amend)) @@ -140,17 +140,17 @@ Rspec: Add to your `.rspec_parallel` (or `.rspec`), but can also be used via `-- --format progress --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log -To use a custom logfile location (default: `tmp/parallel_runtime_rspec.log`), use the CLI: `parallel_test spec -t rspec --runtime-log my.log` - ### Minitest Add to your `test_helper.rb`: ```ruby -require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME'] +if ENV['RECORD_RUNTIME'] + require 'parallel_tests/test/runtime_logger' + # ParallelTests::Test::RuntimeLogger.logfile = "tmp/parallel_runtime_test.log" # where to write it +end ``` -results will be logged to `tmp/parallel_runtime_test.log` when `RECORD_RUNTIME` is set, -so it is not always required or overwritten. +results will be logged when `RECORD_RUNTIME` is set, so it is not always required or overwritten. Loggers ======= diff --git a/lib/parallel_tests/test/runtime_logger.rb b/lib/parallel_tests/test/runtime_logger.rb index 095208d2..fa16a46c 100644 --- a/lib/parallel_tests/test/runtime_logger.rb +++ b/lib/parallel_tests/test/runtime_logger.rb @@ -8,6 +8,8 @@ class RuntimeLogger @@prepared = false class << self + attr_writer :logfile + def log_test_run(test) prepare @@ -66,7 +68,7 @@ def message(test, delta) end def logfile - ParallelTests::Test::Runner.runtime_log + @logfile || ParallelTests::Test::Runner.runtime_log end end end diff --git a/spec/parallel_tests/test/runtime_logger_spec.rb b/spec/parallel_tests/test/runtime_logger_spec.rb index 0e038c0c..28fe3796 100644 --- a/spec/parallel_tests/test/runtime_logger_spec.rb +++ b/spec/parallel_tests/test/runtime_logger_spec.rb @@ -51,4 +51,28 @@ def test_foo ) end end + + it "can write to a custom location" do + skip if RUBY_PLATFORM == "java" # just too slow ... + repo_root = Dir.pwd + + use_temporary_directory do + FileUtils.mkdir "test" + File.write("test/a_test.rb", <<-RUBY) + require 'minitest/autorun' + require 'parallel_tests/test/runtime_logger' + ParallelTests::Test::RuntimeLogger.logfile = "foo.log" + + class Bar < Minitest::Test + def test_foo + assert true + end + end + RUBY + + run_tests(repo_root) + + expect(File.exist?("foo.log")).to eq(true) + end + end end