@@ -7,6 +7,7 @@ import * as fs from "fs";
77import * as os from "os" ;
88import * as path from "path" ;
99import * as sinon from "sinon" ;
10+ import { EventEmitter } from "events" ;
1011import { getAndroidHermesEnabled , getiOSHermesEnabled , runHermesEmitBinaryCommand } from "../script/react-native-utils" ;
1112
1213function getHermesOSBin ( ) : string {
@@ -259,6 +260,83 @@ android {
259260 assert . equal ( fs . readFileSync ( path . join ( outputFolder , bundleName ) , "utf-8" ) , "compiled hermes bundle" ) ;
260261 } ) ;
261262
263+ it ( "keeps Hermes compiler output quiet when compilation succeeds" , async ( ) : Promise < void > => {
264+ writeReactNativeProject ( projectPath , "0.84.1" ) ;
265+
266+ const hermesCompilerPath = path . join (
267+ "node_modules" ,
268+ "hermes-compiler" ,
269+ "hermesc" ,
270+ getHermesOSBin ( ) ,
271+ getHermesCompilerExe ( )
272+ ) ;
273+ writeFile ( path . join ( projectPath , hermesCompilerPath ) ) ;
274+
275+ const outputFolder = path . join ( projectPath , "CodePush" ) ;
276+ const bundleName = "index.android.bundle" ;
277+ writeFile ( path . join ( outputFolder , bundleName ) , "plain js bundle" ) ;
278+
279+ const consoleLog = sandbox . stub ( console , "log" ) ;
280+ const consoleError = sandbox . stub ( console , "error" ) ;
281+ sandbox . stub ( childProcess , "spawn" ) . callsFake ( ( command : string , args : string [ ] ) : any => {
282+ const outputIndex = args . indexOf ( "-out" ) ;
283+ fs . writeFileSync ( args [ outputIndex + 1 ] , "compiled hermes bundle" ) ;
284+
285+ const hermesProcess = new EventEmitter ( ) as any ;
286+ hermesProcess . stdout = new EventEmitter ( ) ;
287+ hermesProcess . stderr = new EventEmitter ( ) ;
288+
289+ setImmediate ( ( ) => {
290+ hermesProcess . stdout . emit ( "data" , Buffer . from ( "verbose stdout\n" ) ) ;
291+ hermesProcess . stderr . emit ( "data" , Buffer . from ( "verbose stderr\n" ) ) ;
292+ hermesProcess . emit ( "close" , 0 , null ) ;
293+ } ) ;
294+
295+ return hermesProcess ;
296+ } ) ;
297+
298+ await runHermesEmitBinaryCommand ( bundleName , outputFolder , null , [ ] , null ) ;
299+
300+ sinon . assert . notCalled ( consoleLog ) ;
301+ sinon . assert . notCalled ( consoleError ) ;
302+ } ) ;
303+
304+ it ( "includes buffered Hermes compiler output when compilation fails" , async ( ) : Promise < void > => {
305+ writeReactNativeProject ( projectPath , "0.84.1" ) ;
306+
307+ const hermesCompilerPath = path . join (
308+ "node_modules" ,
309+ "hermes-compiler" ,
310+ "hermesc" ,
311+ getHermesOSBin ( ) ,
312+ getHermesCompilerExe ( )
313+ ) ;
314+ writeFile ( path . join ( projectPath , hermesCompilerPath ) ) ;
315+
316+ const outputFolder = path . join ( projectPath , "CodePush" ) ;
317+ const bundleName = "index.android.bundle" ;
318+ writeFile ( path . join ( outputFolder , bundleName ) , "plain js bundle" ) ;
319+
320+ sandbox . stub ( childProcess , "spawn" ) . callsFake ( ( ) : any => {
321+ const hermesProcess = new EventEmitter ( ) as any ;
322+ hermesProcess . stdout = new EventEmitter ( ) ;
323+ hermesProcess . stderr = new EventEmitter ( ) ;
324+
325+ setImmediate ( ( ) => {
326+ hermesProcess . stdout . emit ( "data" , Buffer . from ( "useful stdout\n" ) ) ;
327+ hermesProcess . stderr . emit ( "data" , Buffer . from ( "useful stderr\n" ) ) ;
328+ hermesProcess . emit ( "close" , 1 , null ) ;
329+ } ) ;
330+
331+ return hermesProcess ;
332+ } ) ;
333+
334+ await assert . rejects (
335+ ( ) => runHermesEmitBinaryCommand ( bundleName , outputFolder , null , [ ] , null ) ,
336+ / H e r m e s s t d o u t : \n u s e f u l s t d o u t [ \s \S ] * H e r m e s s t d e r r : \n u s e f u l s t d e r r /
337+ ) ;
338+ } ) ;
339+
262340 it ( "uses explicit Gradle hermesCommand before package autodetection" , async ( ) : Promise < void > => {
263341 writeReactNativeProject ( projectPath , "0.84.1" ) ;
264342 const customHermesCommand = path . join ( ".." , ".." , "custom-hermes" , "%OS-BIN%" , getHermesCompilerExe ( ) ) ;
0 commit comments