@@ -675,14 +675,24 @@ function cleanTestDirs() {
675675
676676// used to pass data from jake command line directly to run.js
677677function writeTestConfigFile ( testConfigFile , tests , light , stackTraceLimit ) {
678- console . log ( 'Running test(s): ' + tests ) ;
679- var testConfig = { test : [ tests ] , light : light } ;
678+ var testConfig ;
679+ if ( tests ) {
680+ console . log ( 'Running test(s): ' + tests ) ;
681+ ( testConfig || ( testConfig = { } ) ) . tests = [ tests ] ;
682+ }
683+
684+ if ( light ) {
685+ ( testConfig || ( testConfig = { } ) ) . light = light ;
686+ }
687+
680688 if ( / ^ ( \d + | f u l l ) $ / . test ( stackTraceLimit ) ) {
681- testConfig . stackTraceLimit = stackTraceLimit ;
689+ ( testConfig || ( testConfig = { } ) ) . stackTraceLimit = stackTraceLimit ;
682690 }
683691
684- var testConfigContents = JSON . stringify ( testConfig ) ;
685- fs . writeFileSync ( 'test.config' , testConfigContents ) ;
692+ if ( testConfig ) {
693+ var testConfigContents = JSON . stringify ( testConfig ) ;
694+ fs . writeFileSync ( testConfigFile , testConfigContents ) ;
695+ }
686696}
687697
688698function deleteTemporaryProjectOutput ( ) {
@@ -700,9 +710,7 @@ function runTestsAndWriteOutput(file) {
700710 fs . unlinkSync ( testConfigFile ) ;
701711 }
702712
703- if ( tests || light ) {
704- writeTestConfigFile ( testConfigFile , tests , light , 10 ) ;
705- }
713+ writeTestConfigFile ( testConfigFile , tests , light , 10 ) ;
706714
707715 if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
708716 testTimeout = 100000 ;
@@ -719,11 +727,16 @@ function runTestsAndWriteOutput(file) {
719727
720728 var cmd = "mocha " + args . join ( " " ) ;
721729 console . log ( cmd ) ;
722- var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true } ) ;
730+ var p = child_process . spawn (
731+ process . platform === "win32" ? "cmd" : "/bin/sh" ,
732+ process . platform === "win32" ? [ "/c" , cmd ] : [ "-c" , cmd ] , {
733+ windowsVerbatimArguments : true
734+ } ) ;
735+
723736 var out = fs . createWriteStream ( file ) ;
724737 var tapRange = / ^ ( \d + ) \. \. ( \d + ) (?: $ | \r \n ? | \n ) / ;
725738 var tapOk = / ^ o k \s / ;
726- var tapNotOk = / ^ n o t \s o k / ;
739+ var tapNotOk = / ^ n o t \s o k \s / ;
727740 var tapComment = / ^ # / ;
728741 var typeError = / ^ \s + T y p e E r r o r : / ;
729742 var debugError = / ^ \s + E r r o r : \s D e b u g \s F a i l u r e \. / ;
@@ -736,29 +749,46 @@ function runTestsAndWriteOutput(file) {
736749 var typeErrorCount = 0 ;
737750 var debugErrorCount = 0 ;
738751
739- ex . addListener ( "stdout" , function ( output ) {
740- var m = tapRange . exec ( output ) ;
752+ var rl = readline . createInterface ( {
753+ input : p . stdout ,
754+ terminal : false
755+ } ) ;
756+
757+ function updateProgress ( percentComplete ) {
758+ progress . update ( percentComplete ,
759+ /*foregroundColor*/ failureCount > 0
760+ ? "red"
761+ : successCount === expectedTestCount
762+ ? "green"
763+ : "cyan" ,
764+ /*backgroundColor*/ "gray"
765+ ) ;
766+ }
767+
768+ rl . on ( "line" , function ( line ) {
769+ var m = tapRange . exec ( line ) ;
741770 if ( m ) {
742771 expectedTestCount = parseInt ( m [ 2 ] ) ;
743772 return ;
744773 }
745774
746- out . write ( output ) ;
747-
748- if ( tapOk . test ( output ) ) {
775+ if ( tapOk . test ( line ) ) {
776+ out . write ( line . replace ( / ^ o k \s + \d + \s + / , "ok " ) + os . EOL ) ;
749777 successCount ++ ;
750778 }
751- else if ( tapNotOk . test ( output ) ) {
779+ else if ( tapNotOk . test ( line ) ) {
780+ out . write ( line . replace ( / ^ n o t \s + o k \s + \d + \s + / , "not ok " ) + os . EOL ) ;
752781 failureCount ++ ;
753782 }
754783 else {
755- if ( tapComment . test ( output ) ) {
756- comments . push ( output . toString ( ) . trim ( ) ) ;
784+ out . write ( line + os . EOL ) ;
785+ if ( tapComment . test ( line ) ) {
786+ comments . push ( line ) ;
757787 }
758- else if ( typeError . test ( output ) ) {
788+ else if ( typeError . test ( line ) ) {
759789 typeErrorCount ++ ;
760790 }
761- else if ( debugError . test ( output ) ) {
791+ else if ( debugError . test ( line ) ) {
762792 debugErrorCount ++ ;
763793 }
764794 return ;
@@ -770,33 +800,7 @@ function runTestsAndWriteOutput(file) {
770800 updateProgress ( percentComplete ) ;
771801 } ) ;
772802
773- function updateProgress ( percentComplete ) {
774- progress . update ( percentComplete ,
775- /*foregroundColor*/ failureCount > 0
776- ? "red"
777- : successCount === expectedTestCount
778- ? "green"
779- : "cyan" ,
780- /*backgroundColor*/ "gray"
781- ) ;
782- }
783-
784- ex . addListener ( "stderr" , function ( output ) {
785- progress . hide ( ) ;
786- process . stderr . write ( output . toString ( ) . trim ( ) + os . EOL ) ;
787- progress . show ( ) ;
788- } ) ;
789- ex . addListener ( "cmdEnd" , function ( ) {
790- if ( progress . visible ) {
791- updateProgress ( 100 ) ;
792- process . stdout . write ( "done." + os . EOL ) ;
793- }
794-
795- console . log ( comments . join ( os . EOL ) ) ;
796- deleteTemporaryProjectOutput ( ) ;
797- complete ( ) ;
798- } ) ;
799- ex . addListener ( "error" , function ( e , status ) {
803+ p . on ( "exit" , function ( status ) {
800804 if ( progress . visible ) {
801805 updateProgress ( 100 ) ;
802806 process . stdout . write ( "done." + os . EOL ) ;
@@ -813,9 +817,13 @@ function runTestsAndWriteOutput(file) {
813817 }
814818
815819 deleteTemporaryProjectOutput ( ) ;
816- fail ( "Process exited with code " + status ) ;
820+ if ( status ) {
821+ fail ( "Process exited with code " + status ) ;
822+ }
823+ else {
824+ complete ( ) ;
825+ }
817826 } ) ;
818- ex . run ( ) ;
819827}
820828
821829function runConsoleTests ( defaultReporter , defaultSubsets ) {
0 commit comments