11import { Yok } from "../../../lib/common/yok" ;
22import { BundlerCompilerService } from "../../../lib/services/bundler/bundler-compiler-service" ;
33import { assert } from "chai" ;
4+ import { EventEmitter } from "events" ;
45import { ErrorsStub } from "../../stubs" ;
56import { IInjector } from "../../../lib/common/definitions/yok" ;
6- import { CONFIG_FILE_NAME_DISPLAY } from "../../../lib/constants" ;
7+ import {
8+ BUNDLER_COMPILATION_COMPLETE ,
9+ CONFIG_FILE_NAME_DISPLAY ,
10+ } from "../../../lib/constants" ;
711
812const iOSPlatformName = "ios" ;
913const androidPlatformName = "android" ;
@@ -28,11 +32,18 @@ function createTestInjector(): IInjector {
2832 testInjector . register ( "hooksService" , { } ) ;
2933 testInjector . register ( "hostInfo" , { } ) ;
3034 testInjector . register ( "options" , { } ) ;
31- testInjector . register ( "logger" , { } ) ;
35+ testInjector . register ( "logger" , {
36+ info : ( ) => ( { } ) ,
37+ trace : ( ) => ( { } ) ,
38+ warn : ( ) => ( { } ) ,
39+ } ) ;
3240 testInjector . register ( "errors" , ErrorsStub ) ;
3341 testInjector . register ( "packageInstallationManager" , { } ) ;
3442 testInjector . register ( "mobileHelper" , { } ) ;
35- testInjector . register ( "cleanupService" , { } ) ;
43+ testInjector . register ( "cleanupService" , {
44+ addKillProcess : async ( ) => ( { } ) ,
45+ removeKillProcess : async ( ) => ( { } ) ,
46+ } ) ;
3647 testInjector . register ( "projectConfigService" , {
3748 getValue : ( key : string , defaultValue ?: string ) => defaultValue ,
3849 } ) ;
@@ -218,6 +229,74 @@ describe("BundlerCompilerService", () => {
218229 `The bundler configuration file ${ bundlerConfigPath } does not exist. Ensure the file exists, or update the path in ${ CONFIG_FILE_NAME_DISPLAY } ` ,
219230 ) ;
220231 } ) ;
232+
233+ it ( "does not emit a live sync event for the initial Vite watch build" , async ( ) => {
234+ const platformData = < any > {
235+ platformNameLowerCase : "ios" ,
236+ appDestinationDirectoryPath : "/platform/app" ,
237+ } ;
238+ const projectData = < any > {
239+ projectDir : "/project" ,
240+ bundler : "vite" ,
241+ bundlerConfigPath : "/project/vite.config.ts" ,
242+ } ;
243+ const prepareData = < any > { hmr : false } ;
244+ const childProcess = new EventEmitter ( ) as EventEmitter & {
245+ stdout : EventEmitter ;
246+ stderr : EventEmitter ;
247+ pid : number ;
248+ } ;
249+
250+ childProcess . stdout = new EventEmitter ( ) ;
251+ childProcess . stderr = new EventEmitter ( ) ;
252+ childProcess . pid = 123 ;
253+
254+ testInjector . resolve ( "options" ) . hostProjectModuleName = "app" ;
255+ ( < any > bundlerCompilerService ) . getBundler = ( ) => "vite" ;
256+ ( < any > bundlerCompilerService ) . startBundleProcess = async ( ) =>
257+ childProcess ;
258+ ( < any > bundlerCompilerService ) . copyViteBundleToNative = ( ) => ( { } ) ;
259+
260+ const emittedEvents : any [ ] = [ ] ;
261+ bundlerCompilerService . on ( BUNDLER_COMPILATION_COMPLETE , ( data ) => {
262+ emittedEvents . push ( data ) ;
263+ } ) ;
264+
265+ const compilePromise = bundlerCompilerService . compileWithWatch (
266+ platformData ,
267+ projectData ,
268+ prepareData ,
269+ ) ;
270+ await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
271+
272+ childProcess . emit ( "message" , {
273+ emittedFiles : [ "bundle.mjs" ] ,
274+ buildType : "initial" ,
275+ hash : "hash-1" ,
276+ isHMR : false ,
277+ } ) ;
278+
279+ await compilePromise ;
280+ assert . lengthOf ( emittedEvents , 0 ) ;
281+
282+ childProcess . emit ( "message" , {
283+ emittedFiles : [ "bundle.mjs" ] ,
284+ buildType : "incremental" ,
285+ hash : "hash-2" ,
286+ isHMR : false ,
287+ } ) ;
288+
289+ assert . lengthOf ( emittedEvents , 1 ) ;
290+ assert . deepStrictEqual ( emittedEvents [ 0 ] , {
291+ files : [ "/platform/app/app/bundle.mjs" ] ,
292+ hasOnlyHotUpdateFiles : false ,
293+ hmrData : {
294+ hash : "hash-2" ,
295+ fallbackFiles : [ ] ,
296+ } ,
297+ platform : "ios" ,
298+ } ) ;
299+ } ) ;
221300 } ) ;
222301
223302 describe ( "compileWithoutWatch" , ( ) => {
0 commit comments