@@ -13,9 +13,8 @@ def test_app_size_action(fake_aab_size:, fake_apks:, expected_payload:, **other_
13
13
14
14
if other_action_args [ :include_split_sizes ] != false
15
15
# Arrange: fake that apkanalyzer exists
16
- ENV [ 'ANDROID_SDK_ROOT' ] = '__ANDROID_SDK_ROOT__FOR_TESTS__'
17
- apkanalyzer_bin = File . join ( '__ANDROID_SDK_ROOT__FOR_TESTS__' , 'cmdline-tools' , 'latest' , 'bin' , 'apkanalyzer' )
18
- allow ( File ) . to receive ( :executable? ) . with ( apkanalyzer_bin ) . and_return ( true )
16
+ fake_apkanalyzer_path = './fake_apkanalyzer_bin'
17
+ allow ( described_class ) . to receive ( :apkanalyzer_binary! ) . and_return ( fake_apkanalyzer_path )
19
18
20
19
# Arrange: fake that bundletool exists and mock its call to create fake apks with corresponding apkanalyzer calls mocks
21
20
allow ( Fastlane ::Action ) . to receive ( :sh ) . with ( 'command' , '-v' , 'bundletool' , anything )
@@ -25,8 +24,8 @@ def test_app_size_action(fake_aab_size:, fake_apks:, expected_payload:, **other_
25
24
fake_apks . each do |apk_name , sizes |
26
25
apk_path = File . join ( bundletool_tmpdir , 'splits' , apk_name . to_s )
27
26
File . write ( apk_path , "Fake APK file (#{ sizes } )" )
28
- allow ( Fastlane ::Action ) . to receive ( :sh ) . with ( apkanalyzer_bin , 'apk' , 'file-size' , apk_path , anything ) . and_return ( sizes [ 0 ] . to_s )
29
- allow ( Fastlane ::Action ) . to receive ( :sh ) . with ( apkanalyzer_bin , 'apk' , 'download-size' , apk_path , anything ) . and_return ( sizes [ 1 ] . to_s )
27
+ allow ( Fastlane ::Action ) . to receive ( :sh ) . with ( fake_apkanalyzer_path , 'apk' , 'file-size' , apk_path , anything ) . and_return ( sizes [ 0 ] . to_s )
28
+ allow ( Fastlane ::Action ) . to receive ( :sh ) . with ( fake_apkanalyzer_path , 'apk' , 'download-size' , apk_path , anything ) . and_return ( sizes [ 1 ] . to_s )
30
29
end
31
30
end
32
31
end
@@ -51,87 +50,107 @@ def test_app_size_action(fake_aab_size:, fake_apks:, expected_payload:, **other_
51
50
end
52
51
53
52
context 'when `include_split_sizes` is turned off' do
54
- it 'generates the expected payload compressed by default' do
55
- expected = {
56
- meta : [
57
- { name : 'Platform' , value : 'Android' } ,
58
- { name : 'App Name' , value : 'my-app' } ,
59
- { name : 'App Version' , value : '10.2-rc-3' } ,
60
- { name : 'Product Flavor' , value : 'Vanilla' } ,
61
- { name : 'Build Type' , value : 'Release' } ,
62
- { name : 'Source' , value : 'unit-test' } ,
63
- ] ,
64
- metrics : [
65
- { name : 'AAB File Size' , value : 123_456 } ,
66
- ]
67
- }
68
-
69
- test_app_size_action (
70
- fake_aab_size : 123_456 ,
71
- fake_apks : { } ,
72
- expected_payload : expected ,
73
- app_name : 'my-app' ,
74
- app_version_name : '10.2-rc-3' ,
75
- product_flavor : 'Vanilla' ,
76
- build_type : 'Release' ,
77
- source : 'unit-test' ,
78
- include_split_sizes : false
79
- )
53
+ context 'when only providing an `aab_path`' do
54
+ it 'generates the expected payload compressed by default' do
55
+ expected = {
56
+ meta : [
57
+ { name : 'Platform' , value : 'Android' } ,
58
+ { name : 'App Name' , value : 'my-app' } ,
59
+ { name : 'App Version' , value : '10.2-rc-3' } ,
60
+ { name : 'Product Flavor' , value : 'Vanilla' } ,
61
+ { name : 'Build Type' , value : 'Release' } ,
62
+ { name : 'Source' , value : 'unit-test' } ,
63
+ ] ,
64
+ metrics : [
65
+ { name : 'AAB File Size' , value : 123_456 } ,
66
+ ]
67
+ }
68
+
69
+ test_app_size_action (
70
+ fake_aab_size : 123_456 ,
71
+ fake_apks : { } ,
72
+ expected_payload : expected ,
73
+ app_name : 'my-app' ,
74
+ app_version_name : '10.2-rc-3' ,
75
+ product_flavor : 'Vanilla' ,
76
+ build_type : 'Release' ,
77
+ source : 'unit-test' ,
78
+ include_split_sizes : false
79
+ )
80
+ end
81
+
82
+ it 'generates the expected payload uncompressed when disabling gzip' do
83
+ expected = {
84
+ meta : [
85
+ { name : 'Platform' , value : 'Android' } ,
86
+ { name : 'App Name' , value : 'my-app' } ,
87
+ { name : 'App Version' , value : '10.2-rc-3' } ,
88
+ { name : 'Product Flavor' , value : 'Vanilla' } ,
89
+ { name : 'Build Type' , value : 'Release' } ,
90
+ { name : 'Source' , value : 'unit-test' } ,
91
+ ] ,
92
+ metrics : [
93
+ { name : 'AAB File Size' , value : 123_456 } ,
94
+ ]
95
+ }
96
+
97
+ test_app_size_action (
98
+ fake_aab_size : 123_456 ,
99
+ fake_apks : { } ,
100
+ expected_payload : expected ,
101
+ app_name : 'my-app' ,
102
+ app_version_name : '10.2-rc-3' ,
103
+ product_flavor : 'Vanilla' ,
104
+ build_type : 'Release' ,
105
+ source : 'unit-test' ,
106
+ include_split_sizes : false ,
107
+ use_gzip_content_encoding : false
108
+ )
109
+ end
80
110
end
81
111
82
- it 'generates the expected payload uncompressed when disabling gzip' do
83
- expected = {
84
- meta : [
85
- { name : 'Platform' , value : 'Android' } ,
86
- { name : 'App Name' , value : 'my-app' } ,
87
- { name : 'App Version' , value : '10.2-rc-3' } ,
88
- { name : 'Product Flavor' , value : 'Vanilla' } ,
89
- { name : 'Build Type' , value : 'Release' } ,
90
- { name : 'Source' , value : 'unit-test' } ,
91
- ] ,
92
- metrics : [
93
- { name : 'AAB File Size' , value : 123_456 } ,
94
- ]
95
- }
96
-
97
- test_app_size_action (
98
- fake_aab_size : 123_456 ,
99
- fake_apks : { } ,
100
- expected_payload : expected ,
101
- app_name : 'my-app' ,
102
- app_version_name : '10.2-rc-3' ,
103
- product_flavor : 'Vanilla' ,
104
- build_type : 'Release' ,
105
- source : 'unit-test' ,
106
- include_split_sizes : false ,
107
- use_gzip_content_encoding : false
108
- )
112
+ context 'when only providing an `universal_apk_path`' do
113
+ it 'generates the expected payload containing the apk file size'
114
+ end
115
+
116
+ context 'when providing both an `aab_path` and an `universal_apk_path`' do
117
+ it 'generates the expected payload containing the aab and universal apk file size'
109
118
end
110
119
end
111
120
112
121
context 'when keeping the default value of `include_split_sizes` turned on' do
113
- it 'generates the expected payload containing the aab file size and optimized split sizes' do
114
- expected_fixture = File . join ( test_data_dir , 'android-metrics-payload.json' )
115
- expected = JSON . parse ( File . read ( expected_fixture ) )
116
-
117
- test_app_size_action (
118
- fake_aab_size : 987_654_321 ,
119
- fake_apks : {
120
- 'base-arm64_v8a.apk' : [ 164_080 , 64_080 ] ,
121
- 'base-arm64_v8a_2.apk' : [ 164_082 , 64_082 ] ,
122
- 'base-armeabi.apk' : [ 150_000 , 50_000 ] ,
123
- 'base-armeabi_2.apk' : [ 150_002 , 50_002 ] ,
124
- 'base-armeabi_v7a.apk' : [ 150_070 , 50_070 ] ,
125
- 'base-armeabi_v7a_2.apk' : [ 150_072 , 50_072 ]
126
- } ,
127
- expected_payload : expected ,
128
- app_name : 'wordpress' ,
129
- app_version_name : '19.8-rc-3' ,
130
- app_version_code : 1214 ,
131
- product_flavor : 'Vanilla' ,
132
- build_type : 'Release' ,
133
- source : 'unit-test'
134
- )
122
+ context 'when only providing an `aab_path`' do
123
+ it 'generates the expected payload containing the aab file size and optimized split sizes' do
124
+ expected_fixture = File . join ( test_data_dir , 'android-metrics-payload.json' )
125
+ expected = JSON . parse ( File . read ( expected_fixture ) )
126
+
127
+ test_app_size_action (
128
+ fake_aab_size : 987_654_321 ,
129
+ fake_apks : {
130
+ 'base-arm64_v8a.apk' : [ 164_080 , 64_080 ] ,
131
+ 'base-arm64_v8a_2.apk' : [ 164_082 , 64_082 ] ,
132
+ 'base-armeabi.apk' : [ 150_000 , 50_000 ] ,
133
+ 'base-armeabi_2.apk' : [ 150_002 , 50_002 ] ,
134
+ 'base-armeabi_v7a.apk' : [ 150_070 , 50_070 ] ,
135
+ 'base-armeabi_v7a_2.apk' : [ 150_072 , 50_072 ]
136
+ } ,
137
+ expected_payload : expected ,
138
+ app_name : 'wordpress' ,
139
+ app_version_name : '19.8-rc-3' ,
140
+ app_version_code : 1214 ,
141
+ product_flavor : 'Vanilla' ,
142
+ build_type : 'Release' ,
143
+ source : 'unit-test'
144
+ )
145
+ end
146
+ end
147
+
148
+ context 'when only providing an `universal_apk_path`' do
149
+ it 'generates the expected payload containing the apk file size and optimized file and download sizes'
150
+ end
151
+
152
+ context 'when providing both an `aab_path` and an `universal_apk_path`' do
153
+ it 'generates the expected payload containing the aab and universal apk file size and optimized file and download sizes for all splits'
135
154
end
136
155
end
137
156
end
0 commit comments