Skip to content

Commit e8bb9a8

Browse files
authored
Merge pull request #403 from wordpress-mobile/ftl-exclude
FTL: Support providing a `--test-targets` filter
2 parents eab670b + 9036f30 commit e8bb9a8

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _None_
1111
### New Features
1212

1313
- 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]
14+
- Add a `test_targets` parameter to the `android_firebase_test` action to be able to filter the tests to be run. [#403]
1415

1516
### Bug Fixes
1617

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def self.run(params)
3333
apk_path: params[:apk_path],
3434
test_apk_path: params[:test_apk_path],
3535
device: device,
36+
test_targets: params[:test_targets],
3637
type: params[:type]
3738
)
3839

@@ -106,6 +107,13 @@ def self.available_options
106107
UI.user_error!("Invalid test APK: #{value}") unless File.exist?(value)
107108
end
108109
),
110+
FastlaneCore::ConfigItem.new(
111+
key: :test_targets,
112+
description: 'A list of one or more test target filters to apply',
113+
type: String,
114+
optional: true,
115+
default_value: nil
116+
),
109117
FastlaneCore::ConfigItem.new(
110118
key: :model,
111119
description: 'The device model to use to run the test',

lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ def self.preflight(verify_gcloud_binary: true, verify_logged_in: true)
2020
# @param [FirebaseDevice] device The virtual device to run tests on.
2121
# @param [String] type The type of test to run.
2222
#
23-
def self.run_tests(project_id:, apk_path:, test_apk_path:, device:, type: 'instrumentation')
23+
def self.run_tests(project_id:, apk_path:, test_apk_path:, device:, test_targets: nil, type: 'instrumentation')
2424
raise "Unable to find apk: #{apk_path}" unless File.file?(apk_path)
2525
raise "Unable to find apk: #{test_apk_path}" unless File.file?(test_apk_path)
2626
raise "Invalid Type: #{type}" unless VALID_TEST_TYPES.include?(type)
2727

28-
command = Shellwords.join [
29-
'gcloud', 'firebase', 'test', 'android', 'run',
30-
'--project', project_id,
31-
'--type', type,
32-
'--app', apk_path,
33-
'--test', test_apk_path,
34-
'--device', device.to_s,
35-
'--verbosity', 'info',
36-
]
28+
params = {
29+
project: project_id,
30+
type: type,
31+
app: apk_path,
32+
test: test_apk_path,
33+
'test-targets': test_targets,
34+
device: device.to_s,
35+
verbosity: 'info'
36+
}.compact.flat_map { |k, v| ["--#{k}", v] }
37+
command = Shellwords.join(['gcloud', 'firebase', 'test', 'android', 'run', *params])
3738

3839
log_file_path = Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH]
3940

spec/firebase_test_runner_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
run_tests
3232
end
3333

34+
it 'includes and properly escapes the test targets if any are provided' do
35+
allow(Fastlane::Action).to receive('sh').with(
36+
"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}"
37+
)
38+
run_tests(test_targets: 'notPackage org.wordpress.android.ui.screenshots')
39+
end
40+
3441
it 'properly escapes the app path' do
3542
temp_file_path = File.join(Dir.tmpdir(), 'path with spaces.txt')
3643
expected_temp_file_path = File.join(Dir.tmpdir(), 'path\ with\ spaces.txt')
@@ -66,13 +73,14 @@
6673
expect { run_tests(type: 'foo') }.to raise_exception('Invalid Type: foo')
6774
end
6875

69-
def run_tests(project_id: 'foo-bar-baz', apk_path: default_file, test_apk_path: default_file, device: 'device', type: 'instrumentation')
76+
def run_tests(project_id: 'foo-bar-baz', apk_path: default_file, test_apk_path: default_file, device: 'device', test_targets: nil, type: 'instrumentation')
7077
Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] = runner_temp_file
7178
described_class.run_tests(
7279
project_id: project_id,
7380
apk_path: apk_path,
7481
test_apk_path: test_apk_path,
7582
device: device,
83+
test_targets: test_targets,
7684
type: type
7785
)
7886
end

0 commit comments

Comments
 (0)