@@ -19,11 +19,13 @@ function runTest(args, outputFile) {
1919 console . log ( `Status: ${ result . status . toString ( ) } ` ) ;
2020 console . log ( `Output: ${ result . stdout . toString ( ) } ` ) ;
2121 console . log ( `Error: ${ result . stderr . toString ( ) } ` ) ;
22+ return result ;
2223}
2324
2425function runAllTests ( ) {
2526
2627 let success = true ;
28+ let testResult ;
2729
2830 // test sld to qgis
2931 let outputFile = 'output.qml' ;
@@ -82,6 +84,39 @@ function runAllTests() {
8284 success = false ;
8385 }
8486
87+ // test writing only styles to stdout
88+ args = [ 'start' , '--' , '-s' , 'sld' , '-t' , 'sld' , 'testdata/sld/point_simplepoint.sld' ] ;
89+ testResult = runTest ( args , outputFile ) ;
90+
91+ const stdout = testResult . stdout . toString ( ) ;
92+ // We have to remove the first 4 lines of the output
93+ // since we are running the tests via npm test which
94+ // adds the command itself to stdout.
95+ const cleanedStdout = stdout . split ( '\n' ) . slice ( 4 ) . join ( '\n' ) ;
96+ console . log ( `stdout: ${ cleanedStdout } ` ) ;
97+ if ( ! cleanedStdout . startsWith ( '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' ) ) {
98+ console . log ( 'Expected SLD output not found in stdout' ) ;
99+ success = false ;
100+ }
101+
102+ // test writing everything else to stderr
103+ args = [ 'start' , '--' , '-s' , 'sld' , '-t' , 'sld' , 'testdata/sld/point_simplepoint.sld' ] ;
104+ testResult = runTest ( args , outputFile ) ;
105+
106+ if ( ! testResult . stderr . toString ( ) . includes ( 'translated successfully' ) ) {
107+ console . log ( 'Expected translation success message not found in stderr' ) ;
108+ success = false ;
109+ }
110+
111+ // test not writing interactive messages in quiet mode
112+ args = [ 'start' , '--' , '-s' , 'sld' , '-t' , 'sld' , 'testdata/sld/point_simplepoint.sld' , '--quiet' ] ;
113+ testResult = runTest ( args , outputFile ) ;
114+
115+ if ( testResult . stderr . toString ( ) . includes ( 'translated successfully' ) ) {
116+ console . log ( 'Expected no interactive messages in quiet mode' ) ;
117+ success = false ;
118+ }
119+
85120 return success ;
86121}
87122
0 commit comments