Skip to content

Commit 94a832d

Browse files
committed
test: add smoke test for bankai start
1 parent 964fed3 commit 94a832d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"dependency-check": "^2.6.0",
5252
"is-html": "^1.0.0",
5353
"istanbul": "^0.4.4",
54+
"openport": "0.0.4",
5455
"standard": "^8.0.0",
5556
"tape": "^4.6.0"
5657
},

test/index.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
'use strict'
2+
3+
const childProcess = require('child_process')
14
const getPort = require('get-server-port')
25
const browserify = require('browserify')
36
const concat = require('concat-stream')
7+
const openport = require('openport')
48
const isHtml = require('is-html')
9+
const bankai = require('../')
510
const http = require('http')
611
const path = require('path')
712
const test = require('tape')
8-
const bankai = require('../')
913

1014
test('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+
88116
test('__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

Comments
 (0)