@@ -49,21 +49,35 @@ function project(t) {
4949 return root ;
5050}
5151
52- function run ( root , command = "build" , succeeds = true ) {
53- const result = spawnSync ( executable , [ command ] , {
52+ function run ( root , command = "build" , succeeds = true , verbose = false ) {
53+ const result = spawnSync ( executable , verbose ? [ "-vv" , command ] : [ command ] , {
5454 cwd : root ,
5555 env,
5656 encoding : "utf8" ,
5757 timeout : 30_000 ,
5858 } ) ;
59- if ( result . error ) throw result . error ;
60- const output = result . stdout + result . stderr ;
59+ const output = ( result . stdout ?? "" ) + ( result . stderr ?? "" ) ;
60+ if ( result . error ) {
61+ throw new Error ( `${ result . error . message } \n${ output } ` , {
62+ cause : result . error ,
63+ } ) ;
64+ }
6165 if ( succeeds ) assert . equal ( result . status , 0 , output ) ;
6266 else
6367 assert . notEqual ( result . status , 0 , "Expected Rewatch to reject the project" ) ;
6468 return output ;
6569}
6670
71+ function compilerArgs ( root , file ) {
72+ const result = spawnSync ( executable , [ "compiler-args" , join ( "src" , file ) ] , {
73+ cwd : root ,
74+ env,
75+ encoding : "utf8" ,
76+ } ) ;
77+ assert . equal ( result . status , 0 , result . stdout + result . stderr ) ;
78+ return JSON . parse ( result . stdout ) . compiler_args . map ( normalizePaths ) ;
79+ }
80+
6781function hasExited ( child ) {
6882 return child . exitCode !== null || child . signalCode !== null ;
6983}
@@ -376,7 +390,10 @@ test("GenType wrappers import the logical platform module without an extension",
376390 "@genType\nlet platform: string" ,
377391 ) ;
378392
379- run ( root ) ;
393+ assert ( compilerArgs ( root , "Button.android.res" ) . includes ( "-bs-gentype" ) ) ;
394+ assert ( ! compilerArgs ( root , "Button.ios.res" ) . includes ( "-bs-gentype" ) ) ;
395+
396+ run ( root , "build" , true , true ) ;
380397
381398 const wrapper = join ( root , "src/Button.gen.tsx" ) ;
382399 assert ( existsSync ( wrapper ) , `Missing ${ wrapper } ` ) ;
@@ -595,22 +612,15 @@ test("a failed build records newly emitted platform outputs for later removal",
595612
596613test ( "compiler-args reports the logical platform compilation" , t => {
597614 const root = project ( t ) ;
598- const result = spawnSync (
599- executable ,
600- [ "compiler-args" , join ( "src" , "Button.ios.res" ) ] ,
601- { cwd : root , env, encoding : "utf8" } ,
602- ) ;
603- assert . equal ( result . status , 0 , result . stdout + result . stderr ) ;
604- const { compiler_args : rawCompilerArgs } = JSON . parse ( result . stdout ) ;
605- const compilerArgs = rawCompilerArgs . map ( normalizePaths ) ;
606- assert ( compilerArgs . includes ( "-bs-platform-interface" ) ) ;
615+ const args = compilerArgs ( root , "Button.ios.res" ) ;
616+ assert ( args . includes ( "-bs-platform-interface" ) ) ;
607617 assert (
608- compilerArgs . includes ( "__platform/ios/Button.cmj" ) ,
609- compilerArgs . join ( " " ) ,
618+ args . includes ( "__platform/ios/Button.cmj" ) ,
619+ args . join ( " " ) ,
610620 ) ;
611621 assert (
612- compilerArgs . some ( argument => argument . includes ( "commonjs:lib/js/src:.ios.js" ) ) ,
613- compilerArgs . join ( " " ) ,
622+ args . some ( argument => argument . includes ( "commonjs:lib/js/src:.ios.js" ) ) ,
623+ args . join ( " " ) ,
614624 ) ;
615- assert ( compilerArgs . includes ( "-bs-read-cmi" ) ) ;
625+ assert ( args . includes ( "-bs-read-cmi" ) ) ;
616626} ) ;
0 commit comments