Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalparadox committed Nov 12, 2012
1 parent 343f3e4 commit 677fac1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ global.should = global.chai.should();
* Chai Plugins
*/

//global.chai.use(require('chai-spies'));
global.chai.use(require('chai-spies'));
//global.chai.use(require('chai-http'));

/*!
Expand Down
3 changes: 2 additions & 1 deletion test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/chai/chai.js"></script>
<script src="../../node_modules/chai-spies/chai-spies.js"></script>
<script>
mocha.setup('bdd')
var should = chai.should();
Expand All @@ -14,7 +15,7 @@
<script>
dag = require('breeze-dag');
</script>
<!-- <script src="../test.js"></script> -->
<script src="../dag.js"></script>
<script>onload = function () {
if (window.mochaPhantomJS) mochaPhantomJS.run()
else mocha.run();
Expand Down
61 changes: 61 additions & 0 deletions test/dag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe('dag', function () {
it('should run a set of edges in threads', function (done) {
var deps = [
[ null, 'a' ]
, [ 'a', 'b' ]
, [ 'a', 'c' ]
, [ 'a', 'f' ]
, [ 'd', 'e' ]
, [ 'b', 'd' ]
];

var spy = chai.spy(function (e, next) {
setTimeout(next, 100);
});

dag(deps, 2, spy, function (err) {
should.not.exist(err);
spy.should.have.been.called.exactly(6);
done();
});
});

it('should bail on error', function (done) {
var deps = [
[ 'a', 'b' ]
, [ 'a', 'c' ]
, [ 'd', 'e' ]
, [ 'b', 'd' ]
];

var spy = chai.spy(function (e, next) {
if (e === 'c') return next('err');
setTimeout(next, 100);
});

dag(deps, 2, spy, function (err) {
err.should.equal('err');
spy.should.have.been.called.exactly(3);
done();
});
});

it('should detect cyclical error', function (done) {
var deps = [
[ 'a', 'b' ]
, [ 'b', 'a' ]
];

var spy = chai.spy(function (e, next) {
setTimeout(next, 10);
});

dag(deps, 2, spy, function (err) {
should.exist(err);
err.should.be.instanceof(Error)
.with.property('message', 'b can not come before a');
spy.should.have.not.been.called();
done();
});
});
});

0 comments on commit 677fac1

Please sign in to comment.