@@ -3,25 +3,35 @@ import { Yok } from "../../lib/common/yok";
3
3
import { assert } from "chai" ;
4
4
import * as FsLib from "../../lib/common/file-system" ;
5
5
import * as path from "path" ;
6
- import { ChildProcess } from "../../lib/common/child-process" ;
7
6
import { HostInfo } from "../../lib/common/host-info" ;
8
- import { AndroidToolsInfo } from "../../lib/android-tools-info" ;
9
7
import { Logger } from "../../lib/common/logger" ;
10
8
import * as ErrorsLib from "../../lib/common/errors" ;
11
9
import temp = require( "temp" ) ;
12
10
temp . track ( ) ;
13
11
14
12
describe ( 'androiPluginBuildService' , ( ) => {
15
13
14
+ let execCalled = false ;
16
15
const createTestInjector = ( ) : IInjector => {
17
16
const testInjector = new Yok ( ) ;
18
17
19
18
testInjector . register ( "fs" , FsLib . FileSystem ) ;
20
- testInjector . register ( "childProcess" , ChildProcess ) ;
19
+ testInjector . register ( "childProcess" , {
20
+ exec : ( ) => {
21
+ execCalled = true ;
22
+ }
23
+ } ) ;
21
24
testInjector . register ( "hostInfo" , HostInfo ) ;
22
- testInjector . register ( "androidToolsInfo" , AndroidToolsInfo ) ;
25
+ testInjector . register ( "androidToolsInfo" , {
26
+ getToolsInfo : ( ) => {
27
+ return { } ;
28
+ } ,
29
+ validateInfo : ( ) => {
30
+ return true ;
31
+ }
32
+ } ) ;
23
33
testInjector . register ( "logger" , Logger ) ;
24
- testInjector . register ( "errors" , ErrorsLib ) ;
34
+ testInjector . register ( "errors" , ErrorsLib . Errors ) ;
25
35
testInjector . register ( "options" , { } ) ;
26
36
testInjector . register ( "config" , { } ) ;
27
37
testInjector . register ( "staticConfig" , { } ) ;
@@ -95,6 +105,10 @@ dependencies {
95
105
androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
96
106
} ) ;
97
107
108
+ beforeEach ( ( ) => {
109
+ execCalled = false ;
110
+ } ) ;
111
+
98
112
describe ( 'builds aar' , ( ) => {
99
113
100
114
it ( 'if supported files are in plugin' , async ( ) => {
@@ -106,11 +120,13 @@ dependencies {
106
120
tempPluginDirPath : pluginFolder
107
121
} ;
108
122
109
- const expectedAarName = "my_plugin.aar" ;
110
- await androidBuildPluginService . buildAar ( config ) ;
111
- const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
123
+ try {
124
+ await androidBuildPluginService . buildAar ( config ) ;
125
+ } catch ( e ) {
126
+ /* intentionally left blank */
127
+ }
112
128
113
- assert . isTrue ( hasGeneratedAar ) ;
129
+ assert . isTrue ( execCalled ) ;
114
130
} ) ;
115
131
116
132
it ( 'if android manifest is missing' , async ( ) => {
@@ -122,11 +138,13 @@ dependencies {
122
138
tempPluginDirPath : pluginFolder
123
139
} ;
124
140
125
- const expectedAarName = "my_plugin.aar" ;
126
- await androidBuildPluginService . buildAar ( config ) ;
127
- const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
141
+ try {
142
+ await androidBuildPluginService . buildAar ( config ) ;
143
+ } catch ( e ) {
144
+ /* intentionally left blank */
145
+ }
128
146
129
- assert . isTrue ( hasGeneratedAar ) ;
147
+ assert . isTrue ( execCalled ) ;
130
148
} ) ;
131
149
132
150
it ( 'if there is only an android manifest file' , async ( ) => {
@@ -138,16 +156,18 @@ dependencies {
138
156
tempPluginDirPath : pluginFolder
139
157
} ;
140
158
141
- const expectedAarName = "my_plugin.aar" ;
142
- await androidBuildPluginService . buildAar ( config ) ;
143
- const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
159
+ try {
160
+ await androidBuildPluginService . buildAar ( config ) ;
161
+ } catch ( e ) {
162
+ /* intentionally left blank */
163
+ }
144
164
145
- assert . isTrue ( hasGeneratedAar ) ;
165
+ assert . isTrue ( execCalled ) ;
146
166
} ) ;
147
167
} ) ;
148
168
149
169
describe ( `doesn't build aar ` , ( ) => {
150
- it ( 'if there is only an android manifest file ' , async ( ) => {
170
+ it ( 'if there are no files ' , async ( ) => {
151
171
setUpPluginNativeFolder ( false , false , false ) ;
152
172
const config : IBuildOptions = {
153
173
platformsAndroidDirPath : tempFolder ,
@@ -156,11 +176,13 @@ dependencies {
156
176
tempPluginDirPath : pluginFolder
157
177
} ;
158
178
159
- const expectedAarName = "my_plugin.aar" ;
160
- await androidBuildPluginService . buildAar ( config ) ;
161
- const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
179
+ try {
180
+ await androidBuildPluginService . buildAar ( config ) ;
181
+ } catch ( e ) {
182
+ /* intentionally left blank */
183
+ }
162
184
163
- assert . equal ( hasGeneratedAar , false ) ;
185
+ assert . isFalse ( execCalled ) ;
164
186
} ) ;
165
187
} ) ;
166
188
@@ -178,7 +200,7 @@ dependencies {
178
200
await androidBuildPluginService . migrateIncludeGradle ( config ) ;
179
201
const includeGradleContent = fs . readText ( path . join ( pluginFolder , includeGradleName ) . toString ( ) ) ;
180
202
const productFlavorsAreRemoved = includeGradleContent . indexOf ( "productFlavors" ) === - 1 ;
181
- assert . equal ( productFlavorsAreRemoved , true ) ;
203
+ assert . isTrue ( productFlavorsAreRemoved ) ;
182
204
} ) ;
183
205
} ) ;
184
206
} ) ;
0 commit comments