@@ -3,25 +3,35 @@ import { Yok } from "../../lib/common/yok";
33import { assert } from "chai" ;
44import * as FsLib from "../../lib/common/file-system" ;
55import * as path from "path" ;
6- import { ChildProcess } from "../../lib/common/child-process" ;
76import { HostInfo } from "../../lib/common/host-info" ;
8- import { AndroidToolsInfo } from "../../lib/android-tools-info" ;
97import { Logger } from "../../lib/common/logger" ;
108import * as ErrorsLib from "../../lib/common/errors" ;
119import temp = require( "temp" ) ;
1210temp . track ( ) ;
1311
1412describe ( 'androiPluginBuildService' , ( ) => {
1513
14+ let execCalled = false ;
1615 const createTestInjector = ( ) : IInjector => {
1716 const testInjector = new Yok ( ) ;
1817
1918 testInjector . register ( "fs" , FsLib . FileSystem ) ;
20- testInjector . register ( "childProcess" , ChildProcess ) ;
19+ testInjector . register ( "childProcess" , {
20+ exec : ( ) => {
21+ execCalled = true ;
22+ }
23+ } ) ;
2124 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+ } ) ;
2333 testInjector . register ( "logger" , Logger ) ;
24- testInjector . register ( "errors" , ErrorsLib ) ;
34+ testInjector . register ( "errors" , ErrorsLib . Errors ) ;
2535 testInjector . register ( "options" , { } ) ;
2636 testInjector . register ( "config" , { } ) ;
2737 testInjector . register ( "staticConfig" , { } ) ;
@@ -95,6 +105,10 @@ dependencies {
95105 androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
96106 } ) ;
97107
108+ beforeEach ( ( ) => {
109+ execCalled = false ;
110+ } ) ;
111+
98112 describe ( 'builds aar' , ( ) => {
99113
100114 it ( 'if supported files are in plugin' , async ( ) => {
@@ -106,11 +120,13 @@ dependencies {
106120 tempPluginDirPath : pluginFolder
107121 } ;
108122
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+ }
112128
113- assert . isTrue ( hasGeneratedAar ) ;
129+ assert . isTrue ( execCalled ) ;
114130 } ) ;
115131
116132 it ( 'if android manifest is missing' , async ( ) => {
@@ -122,11 +138,13 @@ dependencies {
122138 tempPluginDirPath : pluginFolder
123139 } ;
124140
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+ }
128146
129- assert . isTrue ( hasGeneratedAar ) ;
147+ assert . isTrue ( execCalled ) ;
130148 } ) ;
131149
132150 it ( 'if there is only an android manifest file' , async ( ) => {
@@ -138,16 +156,18 @@ dependencies {
138156 tempPluginDirPath : pluginFolder
139157 } ;
140158
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+ }
144164
145- assert . isTrue ( hasGeneratedAar ) ;
165+ assert . isTrue ( execCalled ) ;
146166 } ) ;
147167 } ) ;
148168
149169 describe ( `doesn't build aar ` , ( ) => {
150- it ( 'if there is only an android manifest file ' , async ( ) => {
170+ it ( 'if there are no files ' , async ( ) => {
151171 setUpPluginNativeFolder ( false , false , false ) ;
152172 const config : IBuildOptions = {
153173 platformsAndroidDirPath : tempFolder ,
@@ -156,11 +176,13 @@ dependencies {
156176 tempPluginDirPath : pluginFolder
157177 } ;
158178
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+ }
162184
163- assert . equal ( hasGeneratedAar , false ) ;
185+ assert . isFalse ( execCalled ) ;
164186 } ) ;
165187 } ) ;
166188
@@ -178,7 +200,7 @@ dependencies {
178200 await androidBuildPluginService . migrateIncludeGradle ( config ) ;
179201 const includeGradleContent = fs . readText ( path . join ( pluginFolder , includeGradleName ) . toString ( ) ) ;
180202 const productFlavorsAreRemoved = includeGradleContent . indexOf ( "productFlavors" ) === - 1 ;
181- assert . equal ( productFlavorsAreRemoved , true ) ;
203+ assert . isTrue ( productFlavorsAreRemoved ) ;
182204 } ) ;
183205 } ) ;
184206} ) ;
0 commit comments