@@ -4,6 +4,8 @@ import { assert } from "chai";
44import { ErrorsStub } from "../../stubs" ;
55import { IInjector } from "../../../lib/common/definitions/yok" ;
66import { CONFIG_FILE_NAME_DISPLAY } from "../../../lib/constants" ;
7+ import { EventEmitter } from "events" ;
8+ import * as path from "path" ;
79
810const iOSPlatformName = "ios" ;
911const androidPlatformName = "android" ;
@@ -27,12 +29,14 @@ function createTestInjector(): IInjector {
2729 testInjector . register ( "childProcess" , { } ) ;
2830 testInjector . register ( "hooksService" , { } ) ;
2931 testInjector . register ( "hostInfo" , { } ) ;
30- testInjector . register ( "options" , { } ) ;
32+ testInjector . register ( "options" , { hostProjectModuleName : "app" } ) ;
3133 testInjector . register ( "logger" , { } ) ;
3234 testInjector . register ( "errors" , ErrorsStub ) ;
3335 testInjector . register ( "packageInstallationManager" , { } ) ;
3436 testInjector . register ( "mobileHelper" , { } ) ;
35- testInjector . register ( "cleanupService" , { } ) ;
37+ testInjector . register ( "cleanupService" , {
38+ removeKillProcess : async ( ) : Promise < void > => undefined ,
39+ } ) ;
3640 testInjector . register ( "projectConfigService" , {
3741 getValue : ( key : string , defaultValue ?: string ) => defaultValue ,
3842 } ) ;
@@ -221,6 +225,69 @@ describe("BundlerCompilerService", () => {
221225 } ) ;
222226
223227 describe ( "compileWithoutWatch" , ( ) => {
228+ it ( "copies a successful Vite build to the native app" , async ( ) => {
229+ const childProcess = Object . assign ( new EventEmitter ( ) , { pid : 1234 } ) ;
230+ const copies : Array < {
231+ distOutput : string ;
232+ destDir : string ;
233+ failOnError : boolean ;
234+ } > = [ ] ;
235+ ( < any > bundlerCompilerService ) . startBundleProcess = async ( ) =>
236+ childProcess ;
237+ ( < any > bundlerCompilerService ) . copyViteBundleToNative = (
238+ distOutput : string ,
239+ destDir : string ,
240+ _specificFiles : string [ ] ,
241+ failOnError : boolean ,
242+ ) => {
243+ copies . push ( { distOutput, destDir, failOnError } ) ;
244+ } ;
245+ ( < any > testInjector . resolve ( "projectConfigService" ) ) . getValue = ( ) =>
246+ "vite" ;
247+
248+ const compilation = bundlerCompilerService . compileWithoutWatch (
249+ < any > {
250+ platformNameLowerCase : "android" ,
251+ appDestinationDirectoryPath : "/project/platforms/android" ,
252+ } ,
253+ < any > { projectDir : "/project" } ,
254+ < any > { } ,
255+ ) ;
256+ setImmediate ( ( ) => childProcess . emit ( "close" , 0 ) ) ;
257+ await compilation ;
258+
259+ assert . deepEqual ( copies , [
260+ {
261+ distOutput : path . join ( "/project" , ".ns-vite-build" ) ,
262+ destDir : path . join ( "/project/platforms/android" , "app" ) ,
263+ failOnError : true ,
264+ } ,
265+ ] ) ;
266+ } ) ;
267+
268+ it ( "fails when a successful Vite build cannot be copied" , async ( ) => {
269+ const childProcess = Object . assign ( new EventEmitter ( ) , { pid : 1234 } ) ;
270+ ( < any > bundlerCompilerService ) . startBundleProcess = async ( ) =>
271+ childProcess ;
272+ ( < any > bundlerCompilerService ) . copyViteBundleToNative = ( ) => {
273+ throw new Error ( "copy failed" ) ;
274+ } ;
275+ ( < any > testInjector . resolve ( "projectConfigService" ) ) . getValue = ( ) =>
276+ "vite" ;
277+
278+ const compilation = bundlerCompilerService . compileWithoutWatch (
279+ < any > {
280+ platformNameLowerCase : "ios" ,
281+ appDestinationDirectoryPath : "/project/platforms/ios" ,
282+ } ,
283+ < any > { projectDir : "/project" } ,
284+ < any > { } ,
285+ ) ;
286+ setImmediate ( ( ) => childProcess . emit ( "close" , 0 ) ) ;
287+
288+ await assert . isRejected ( compilation , "copy failed" ) ;
289+ } ) ;
290+
224291 it ( "fails when the value set for bundlerConfigPath is not existant file" , async ( ) => {
225292 const bundlerConfigPath = "some path.js" ;
226293 testInjector . resolve ( "fs" ) . exists = ( filePath : string ) =>
0 commit comments