diff --git a/CHANGELOG.md b/CHANGELOG.md index 17ae60810..8b18f1fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ _None_ ### New Features - Propose to retry when the download of GlotPress translations failed for a locale (especially useful for occurrences of `429 - Too Many Requests` quota limits) [#402] +- Add a `test_targets` parameter to the `android_firebase_test` action to be able to filter the tests to be run. [#403] ### Bug Fixes diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb index 07484d64a..c33789d03 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb @@ -33,6 +33,7 @@ def self.run(params) apk_path: params[:apk_path], test_apk_path: params[:test_apk_path], device: device, + test_targets: params[:test_targets], type: params[:type] ) @@ -106,6 +107,13 @@ def self.available_options UI.user_error!("Invalid test APK: #{value}") unless File.exist?(value) end ), + FastlaneCore::ConfigItem.new( + key: :test_targets, + description: 'A list of one or more test target filters to apply', + type: String, + optional: true, + default_value: nil + ), FastlaneCore::ConfigItem.new( key: :model, description: 'The device model to use to run the test', diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb b/lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb index 9f90c0d3d..8310b4253 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb @@ -20,20 +20,21 @@ def self.preflight(verify_gcloud_binary: true, verify_logged_in: true) # @param [FirebaseDevice] device The virtual device to run tests on. # @param [String] type The type of test to run. # - def self.run_tests(project_id:, apk_path:, test_apk_path:, device:, type: 'instrumentation') + def self.run_tests(project_id:, apk_path:, test_apk_path:, device:, test_targets: nil, type: 'instrumentation') raise "Unable to find apk: #{apk_path}" unless File.file?(apk_path) raise "Unable to find apk: #{test_apk_path}" unless File.file?(test_apk_path) raise "Invalid Type: #{type}" unless VALID_TEST_TYPES.include?(type) - command = Shellwords.join [ - 'gcloud', 'firebase', 'test', 'android', 'run', - '--project', project_id, - '--type', type, - '--app', apk_path, - '--test', test_apk_path, - '--device', device.to_s, - '--verbosity', 'info', - ] + params = { + project: project_id, + type: type, + app: apk_path, + test: test_apk_path, + 'test-targets': test_targets, + device: device.to_s, + verbosity: 'info' + }.compact.flat_map { |k, v| ["--#{k}", v] } + command = Shellwords.join(['gcloud', 'firebase', 'test', 'android', 'run', *params]) log_file_path = Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] diff --git a/spec/firebase_test_runner_spec.rb b/spec/firebase_test_runner_spec.rb index 49a2b873c..55efa1656 100644 --- a/spec/firebase_test_runner_spec.rb +++ b/spec/firebase_test_runner_spec.rb @@ -31,6 +31,13 @@ run_tests end + it 'includes and properly escapes the test targets if any are provided' do + allow(Fastlane::Action).to receive('sh').with( + "gcloud firebase test android run --project foo-bar-baz --type instrumentation --app #{default_file} --test #{default_file} --test-targets notPackage\\ org.wordpress.android.ui.screenshots --device device --verbosity info 2>&1 | tee #{runner_temp_file}" + ) + run_tests(test_targets: 'notPackage org.wordpress.android.ui.screenshots') + end + it 'properly escapes the app path' do temp_file_path = File.join(Dir.tmpdir(), 'path with spaces.txt') expected_temp_file_path = File.join(Dir.tmpdir(), 'path\ with\ spaces.txt') @@ -66,13 +73,14 @@ expect { run_tests(type: 'foo') }.to raise_exception('Invalid Type: foo') end - def run_tests(project_id: 'foo-bar-baz', apk_path: default_file, test_apk_path: default_file, device: 'device', type: 'instrumentation') + def run_tests(project_id: 'foo-bar-baz', apk_path: default_file, test_apk_path: default_file, device: 'device', test_targets: nil, type: 'instrumentation') Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] = runner_temp_file described_class.run_tests( project_id: project_id, apk_path: apk_path, test_apk_path: test_apk_path, device: device, + test_targets: test_targets, type: type ) end