提交 b6db59a7 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

testable web server suite

上级 b67d84d2
...@@ -4,7 +4,7 @@ const test = require('tape') ...@@ -4,7 +4,7 @@ const test = require('tape')
const Server = require('../lib/puppet-web-server') const Server = require('../lib/puppet-web-server')
test('Server basic tests', function (t) { test('Server basic tests', function (t) {
t.plan(9) //t.plan(9)
const PORT = 58788 const PORT = 58788
const s = new Server(PORT) const s = new Server(PORT)
...@@ -30,39 +30,49 @@ test('Server basic tests', function (t) { ...@@ -30,39 +30,49 @@ test('Server basic tests', function (t) {
s.emit('logout') s.emit('logout')
t.equal(s.isLogined() , false , 'logouted after logout event') t.equal(s.isLogined() , false , 'logouted after logout event')
s.quit() s.quit() + t.end()
delete s
//t.end()
}) })
test('Server smoking tests', function (t) { test('Server smoking tests', function (t) {
const PORT = 58788 const PORT = 58788
const s = new Server(PORT) const server = new Server(PORT)
t.plan(1) server.init()
console.log(`s.init()`) .then(() => {
s.init().then(() => { t.ok(true, 'server:' + PORT + ' inited')
console.error('s.inited')
const options = require('url').parse(`https://localhost:${PORT}/ping`) const options = require('url').parse(`https://localhost:${PORT}/ding`)
options.rejectUnauthorized = false // permit self-signed CA options.rejectUnauthorized = false // permit self-signed CA
https.get(options, (res) => { https.get(options, (res) => {
console.error('server inited') t.pass('https server inited')
res.on('data', chunk => { res.on('data', chunk => {
t.equal(chunk.toString(), 'pong', 'https get /ping return pong') t.equal(chunk.toString(), 'dong', 'https get /ding return dong')
}) })
}).on('error', e => { }).on('error', e => {
console.error(e) t.fail('https get error:' + e)
t.ok(false, 'https get error')
}) })
s.socketClient.on('pong', (data) => { function testDing() {
console.error('received event pong from socket: ' + data) if (!server.socketClient) {
t.equal(data, 'pong', 'socket io sent ping got pong') console.error('waiting socketClient to connect for 500ms...')
}) setTimeout(testDing, 500)
s.socketClient.emit('ping') return
}
server.socketClient.on('dong', (data) => {
t.equal(data, 'dong', 'socket io sent ding got dong')
server.quit()
t.end()
})
server.socketClient.emit('ding')
}
testDing()
}).catch((e) => {
t.fail('server init promise rejected:' + e)
}) })
console.error('here')
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册