Last active
December 29, 2015 20:49
-
-
Save ishiduca/7726391 to your computer and use it in GitHub Desktop.
socket.ioアプリのテスト(テストに限らないけど)。テストが終わったらすぐにプロセスを終わらせたいんだけど、地味に終わらない。
多分httpのコネクションが切れないからだと思うだけど、どうすりゃいいのか?
Qiitaに記事書いたら消すと思う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var q = module.exports = require('qunitjs') | |
require('qunit-tap')(q, console.log.bind(console)) | |
q.init() | |
q.config.updateRate = 0 | |
q.assert.is = q.assert.strictEqual | |
q.assert.like = function (str, reg, mes) { t.ok(reg.test(str), mes) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var q = require(__dirname + '/qunit/driver') | |
var io, client | |
q.module('socket.io サーバーを接続してテストを終了させる', { | |
setup: function () { | |
io = require('socket.io').listen(8888, {log: false}) | |
io.sockets.on('connection', function (socket) { | |
socket.on('disconnect', function () { | |
console.log('# disconnect "%s"', socket.id) | |
io.server.close() | |
}) | |
socket.emit('message', {foo: 'bar'}) | |
}) | |
io.server.on('close', function () { | |
console.log('# sever close') | |
}) | |
} | |
, teardown: function () { | |
client.disconnect() | |
} | |
}) | |
q.asyncTest('メッセージが届いたらq.start()する', function (t) { | |
client = require('socket.io-client').connect('http://localhost:8888') | |
client.on('connect', function () { | |
t.ok(true, 'client.on("connect")') | |
}) | |
client.on('message', function (data) { | |
t.is(data.foo, 'bar', 'data.foo === "bar"') | |
q.start() | |
}) | |
}) |
Author
ishiduca
commented
Dec 1, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment