Skip to content

Commit

Permalink
Merge pull request #15 from lovebear/tests
Browse files Browse the repository at this point in the history
Tests thanks @LoveBear
  • Loading branch information
ericz committed Feb 22, 2013
2 parents 5ca3711 + 75fe044 commit 238c0ec
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
@@ -1,5 +1,10 @@
{
"name": "peerjs",
"version": "0.1.0",
"description": "PeerJS client library"
"description": "PeerJS client library",
"devDependencies": {
"uglify-js": "*",
"mocha": "*",
"expect.js": "*"
}
}
19 changes: 19 additions & 0 deletions test/adapter.js
@@ -0,0 +1,19 @@
describe('adapter', function() {

it('sets browerisms', function() {
expect(exports.util.browserisms).to.match(/^Firefox||Webkit$/);
})

it('sets RTCPeerConnection', function() {
expect(RTCPeerConnection).to.be.a('function');
})

it('sets RTCSessionDescription', function() {
expect(RTCSessionDescription).to.be.a('function');
})

it('sets getUserMedia', function() {
expect(getUserMedia).to.be.a('function');
})

});
65 changes: 65 additions & 0 deletions test/connection.js
@@ -0,0 +1,65 @@
describe('DataConnection', function() {

it('constructor');

it('inherits from EventEmitter');

it('initialize');

it('_setupOffer', function() {

});

it('_setupDataChannel', function() {

});

it('_startPeerConnection', function() {

});

it('_setupIce', function() {

});

it('_configureDataChannel', function() {

});

it('_makeOffer', function() {

});

it('_makeAnswer', function() {

});

it('_cleanup', function() {

});

it('_handleDataMessage', function() {

});

it('close', function() {

});

it('send', function() {

});

it('handleSDP', function() {

});

it('handleCandidate', function() {

});

it('handleLeave"', function() {

});

});
25 changes: 25 additions & 0 deletions test/peer.js
@@ -0,0 +1,25 @@
describe('Peer', function() {

it('constructor')

it('inherits from EventEmitter')

it('_getId')

it('_init')

it('_handleServerJSONMessage')

it('_processQueue')

it('_abort')

it('_cleanup')

it('_attachConnectionListeners')

it('connect')

it('destroy')

});
23 changes: 23 additions & 0 deletions test/socket.js
@@ -0,0 +1,23 @@
describe('Socket', function() {

it('constructor')

it('inherits from EventEmitter')

it('start')

it('_startWebSocket')

it('_startXhrStream')

it('_handleStream')

it('_setHTTPTimeout')

it('send')

it('close')

it('_wsOpen')

});
35 changes: 35 additions & 0 deletions test/test.html
@@ -0,0 +1,35 @@
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script>
var exports = this;
</script>
<script src="../deps/js-binarypack/lib/bufferbuilder.js"></script>
<script src="../deps/js-binarypack/lib/binarypack.js"></script>
<script src="../deps/EventEmitter/EventEmitter.js"></script>
<script src="../lib/util.js"></script>
<script src="../lib/adapter.js"></script>
<script src="../lib/connection.js"></script>
<script src="../lib/peer.js"></script>
<script src="../lib/socket.js"></script>

<script src="../node_modules/expect.js/expect.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>

<script src="adapter.js"></script>
<script src="util.js"></script>
<script src="connection.js"></script>
<script src="peer.js"></script>
<script src="socket.js"></script>

<script>
mocha.run();
</script>
</body>
</html>
98 changes: 98 additions & 0 deletions test/util.js
@@ -0,0 +1,98 @@
describe('util', function() {

var testRandom = function(fn) {
var i = 0
, generated = {};
while(i < 25) {
var p = fn();
if (generated[p]) throw new Error('not so random')
generated[p] = 1;
i++;
}
}

it('inherits', function() {
function ctor() {}
function superCtor() {}
superCtor.prototype.test = function() { return 5; }
util.inherits(ctor, superCtor);
expect(new ctor()).to.be.a(superCtor);
expect(new ctor().test()).to.be.equal(5);
})

/*
* extend overwrites keys if already exists
* leaves existing keys alone otherwise
*/
it('extend', function() {
var a = {a: 1, b: 2, c: 3, d: 4}
, b = {d: 2};
util.extend(b, a);
expect(b).to.eql(a);
expect(b.d).to.be.equal(4);
b = {z: 2};
util.extend(b, a);
expect(b.z).to.be.equal(2);
})

it('pack', function() {
expect(util.pack).to.be.equal(BinaryPack.pack);
})

it('unpack', function() {
expect(util.unpack).to.be.equal(BinaryPack.unpack);
})

it('randomPort', function() {
testRandom(util.randomPort);
})

// FF no like
it('log', function(done) {
var consolelog = console.log;
// default is false
expect(util.debug).to.be.equal(false);
util.debug = true;
console.log = function() {
var arg = Array.prototype.slice.call(arguments);
expect(arg.join(' ')).to.be.equal('PeerJS: hi');
done();
}
util.log('hi');
// reset
console.log = consolelog;
util.debug = false;
})

it('setZeroTimeout')

it('blobToArrayBuffer', function(done) {
var blob = new Blob(['hi']);
util.blobToArrayBuffer(blob, function(result) {
expect(result.byteLength).to.be.equal(2);
expect(result.slice).to.be.a('function');
expect(result instanceof ArrayBuffer).to.be.equal(true);
done();
});
})

it('blobToBinaryString', function(done) {
var blob = new Blob(['hi']);
util.blobToBinaryString(blob, function(result) {
expect(result).to.equal('hi');
done();
});
})

it('binaryStringToArrayBuffer', function() {
var ba = util.binaryStringToArrayBuffer('\0\0');
expect(ba.byteLength).to.be.equal(2);
expect(ba.slice).to.be.a('function');
expect(ba instanceof ArrayBuffer).to.be.equal(true);
})

it('randomToken', function() {
testRandom(util.randomToken);
})

});

0 comments on commit 238c0ec

Please sign in to comment.