1+ 'use strict'
2+
3+ const childProcess = require ( 'child_process' )
14const getPort = require ( 'get-server-port' )
25const browserify = require ( 'browserify' )
36const concat = require ( 'concat-stream' )
7+ const openport = require ( 'openport' )
48const isHtml = require ( 'is-html' )
9+ const bankai = require ( '../' )
510const http = require ( 'http' )
611const path = require ( 'path' )
712const test = require ( 'tape' )
8- const bankai = require ( '../' )
913
1014test ( 'html' , function ( t ) {
1115 t . test ( 'returns data' , function ( t ) {
@@ -85,6 +89,30 @@ test('js', function (t) {
8589 } )
8690} )
8791
92+ test ( 'start' , function ( t ) {
93+ t . test ( 'start does not throw' , function ( t ) {
94+ t . plan ( 1 )
95+
96+ openport . find ( function ( err , p ) {
97+ const port = err ? 1337 : p
98+
99+ const args = [ 'start' , '--entry=./fixture' , `--port=${ port } ` ]
100+
101+ bin ( args , function ( error , data , child ) {
102+ child . kill ( )
103+
104+ if ( error ) {
105+ return t . fail ( error )
106+ }
107+
108+ const actual = data . toString ( ) . split ( '\n' ) [ 0 ]
109+ const expected = `Started bankai for fixture.js on http://localhost:${ port } `
110+ t . equal ( actual , expected , 'start logs success' )
111+ } )
112+ } )
113+ } )
114+ } )
115+
88116test ( '__END__' , function ( t ) {
89117 t . on ( 'end' , function ( ) {
90118 setTimeout ( function ( ) {
@@ -93,3 +121,20 @@ test('__END__', function (t) {
93121 } )
94122 t . end ( )
95123} )
124+
125+ function bin ( args , cb ) {
126+ const file = path . resolve ( __dirname , '../bin/index.js' )
127+
128+ const child = childProcess . spawn ( file , args , {
129+ cwd : __dirname ,
130+ env : process . env
131+ } )
132+
133+ child . stdout . once ( 'data' , function ( data ) {
134+ cb ( null , data , child )
135+ } )
136+
137+ child . stderr . once ( 'data' , function ( error ) {
138+ cb ( new Error ( error ) , null , child )
139+ } )
140+ }
0 commit comments