@@ -5,6 +5,8 @@ var path = require("path");
55var Module = require ( "module" ) ;
66var protobuf = require ( ".." ) ;
77var fs = require ( "fs" ) ;
8+ var EventEmitter = require ( "events" ) . EventEmitter ;
9+ var child_process = require ( "child_process" ) ;
810
911function cliTest ( test , testFunc ) {
1012 // pbjs does not seem to work with Node v4, so skip this test if we're running on it
@@ -110,6 +112,38 @@ tape.test("pbjs generates correct ES6 static-module imports", function(test) {
110112 } ) ;
111113} ) ;
112114
115+ tape . test ( "pbts passes jsdoc arguments without a shell" , function ( test ) {
116+ var pbts = require ( "../cli/pbts" ) ;
117+ var originalSpawn = child_process . spawn ;
118+ var file = "file with \"quotes\" `backticks` 'apostrophes' and ;.js" ;
119+
120+ test . plan ( 5 ) ;
121+
122+ child_process . spawn = function ( cmd , args , options ) {
123+ var child = new EventEmitter ( ) ;
124+ child . stdout = new EventEmitter ( ) ;
125+ child . stderr = { pipe : function ( ) { } } ;
126+
127+ test . equal ( cmd , process . execPath , "should execute node directly" ) ;
128+ test . ok ( / j s d o c [ \\ / ] j s d o c \. j s $ / . test ( args [ 0 ] ) , "should execute jsdoc directly" ) ;
129+ test . equal ( args [ args . length - 1 ] , file , "should pass file path as a single argument" ) ;
130+ test . equal ( options . stdio , "pipe" , "should pipe jsdoc output" ) ;
131+
132+ process . nextTick ( function ( ) {
133+ child . stdout . emit ( "data" , "declare namespace test {}\n" ) ;
134+ child . stdout . emit ( "end" ) ;
135+ child . emit ( "close" , 0 ) ;
136+ } ) ;
137+
138+ return child ;
139+ } ;
140+
141+ pbts . main ( [ file ] , function ( err ) {
142+ child_process . spawn = originalSpawn ;
143+ test . error ( err , "should generate definitions" ) ;
144+ } ) ;
145+ } ) ;
146+
113147tape . test ( "without null-defaults, absent optional fields have zero values" , function ( test ) {
114148 cliTest ( test , function ( ) {
115149 var root = protobuf . loadSync ( "tests/data/cli/null-defaults.proto" ) ;
0 commit comments