diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1a2d6c..e06094b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +### 2.7.0 + +* Add support for env var `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` to allow accepting file containing test files to run. + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/129 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.6.0...v2.7.0 + ### 2.6.0 * Improve logger to show failed requests URL and when retry will happen diff --git a/README.md b/README.md index 145caa02..9184e15e 100644 --- a/README.md +++ b/README.md @@ -3082,7 +3082,9 @@ The test file pattern and exclude pattern support any glob pattern handled by [` #### How to run a specific list of test files or only some tests from test file? -:information_source: If you don't want to use the pattern [`KNAPSACK_PRO_TEST_FILE_PATTERN`](#how-can-i-run-tests-from-multiple-directories) to define a list of tests to run then read below. +:information_source: If you don't want to use the pattern [`KNAPSACK_PRO_TEST_FILE_PATTERN`](#how-can-i-run-tests-from-multiple-directories) to define a list of tests to run then read below two options. + +**Option 1:** If you want to run a specific list of test files that are explicitly defined by you or auto-generated by some kind of script you created then please use: @@ -3090,7 +3092,24 @@ If you want to run a specific list of test files that are explicitly defined by Note `KNAPSACK_PRO_TEST_FILE_LIST` must be a list of test files comma separated. You can provide line number for tests inside of spec file in case of RSpec (this way you can run only one test or a group of tests from RSpec spec file). You can provide the same file a few times with different test line number. -Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` then below environment variables are ignored: +**Option 2:** + +Similarly, you can also provide a source file containing the test files that you would like to run. For example: +`KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=spec/fixtures/test_file_list_source_file.txt` +And the content of the source file can be any of the format below: + +``` +./spec/test1_spec.rb +spec/test2_spec.rb[1] +./spec/test3_spec.rb[1:2:3:4] +./spec/test4_spec.rb:4 +./spec/test4_spec.rb:5 +``` + +> Note that each of the line must be ending with `\n` the new line. + +Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` or `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` then below environment variables are ignored: + * `KNAPSACK_PRO_TEST_FILE_PATTERN` * `KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN` diff --git a/lib/knapsack_pro/config/env.rb b/lib/knapsack_pro/config/env.rb index 0b7b3d5f..bc3d1c02 100644 --- a/lib/knapsack_pro/config/env.rb +++ b/lib/knapsack_pro/config/env.rb @@ -74,6 +74,10 @@ def test_file_list ENV['KNAPSACK_PRO_TEST_FILE_LIST'] end + def test_file_list_source_file + ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE'] + end + def test_dir ENV['KNAPSACK_PRO_TEST_DIR'] end diff --git a/lib/knapsack_pro/test_file_finder.rb b/lib/knapsack_pro/test_file_finder.rb index c66ba280..457e0645 100644 --- a/lib/knapsack_pro/test_file_finder.rb +++ b/lib/knapsack_pro/test_file_finder.rb @@ -63,6 +63,10 @@ def test_files return KnapsackPro::Config::Env.test_file_list.split(',').map(&:strip) end + if test_file_list_enabled && KnapsackPro::Config::Env.test_file_list_source_file + return File.read(KnapsackPro::Config::Env.test_file_list_source_file).split(/\n/) + end + test_file_paths = Dir.glob(test_file_pattern).uniq excluded_test_file_paths = diff --git a/spec/fixtures/test_file_list_source_file.txt b/spec/fixtures/test_file_list_source_file.txt new file mode 100644 index 00000000..e827c5a0 --- /dev/null +++ b/spec/fixtures/test_file_list_source_file.txt @@ -0,0 +1,5 @@ +./spec/test1_spec.rb +spec/test2_spec.rb[1] +./spec/test3_spec.rb[1:2:3:4] +./spec/test4_spec.rb:4 +./spec/test4_spec.rb:5 diff --git a/spec/knapsack_pro/config/env_spec.rb b/spec/knapsack_pro/config/env_spec.rb index 45531d08..45dbe14e 100644 --- a/spec/knapsack_pro/config/env_spec.rb +++ b/spec/knapsack_pro/config/env_spec.rb @@ -238,6 +238,20 @@ end end + describe '.test_file_list_source_file' do + subject { described_class.test_file_list_source_file } + + context 'when ENV exists' do + let(:test_file_list_source_file) { 'spec/fixtures/test_file_list_source_file.txt' } + before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file }) } + it { should eq test_file_list_source_file } + end + + context "when ENV doesn't exist" do + it { should be_nil } + end + end + describe '.test_dir' do subject { described_class.test_dir } diff --git a/spec/knapsack_pro/test_file_finder_spec.rb b/spec/knapsack_pro/test_file_finder_spec.rb index 56345318..eb4cd4fe 100644 --- a/spec/knapsack_pro/test_file_finder_spec.rb +++ b/spec/knapsack_pro/test_file_finder_spec.rb @@ -154,5 +154,23 @@ end end end + + context 'when KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE is defined' do + let(:test_file_list_source_file) { 'spec/fixtures/test_file_list_source_file.txt' } + + before do + stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file }) + end + + it do + expect(subject).to eq([ + { 'path' => 'spec/test1_spec.rb' }, + { 'path' => 'spec/test2_spec.rb[1]' }, + { 'path' => 'spec/test3_spec.rb[1:2:3:4]' }, + { 'path' => 'spec/test4_spec.rb:4' }, + { 'path' => 'spec/test4_spec.rb:5' }, + ]) + end + end end end