diff --git a/lib/ext.js b/lib/ext.js index 3076d6d8d..31bedf5b1 100755 --- a/lib/ext.js +++ b/lib/ext.js @@ -275,9 +275,6 @@ internals.topoSort = function (ancestorsGraph, length) { } } - if (sorted.length != length) { - throw new Error('Invalid ext input supplied'); // Occurs if before/after set to item's group (but not limited to this case) - } - + Utils.assert(sorted.length === length, 'Invalid ext dependencies detected'); return sorted; }; diff --git a/test/unit/ext.js b/test/unit/ext.js index 18f6e613c..a31f0c2cb 100755 --- a/test/unit/ext.js +++ b/test/unit/ext.js @@ -82,26 +82,56 @@ describe('Ext', function () { }); }); - it('sorts dependencies (2)', function (done) { - - var scenario = [ - { id: '0', before: 'a' }, - { id: '1', after: 'f', group: 'a' }, - { id: '2', before: 'a' }, - { id: '3', before: ['b', 'c'], group: 'a' }, - { id: '4', after: 'c', group: 'b' }, - { id: '5', group: 'c' }, - { id: '6', group: 'd' }, - { id: '7', group: 'e' }, - { id: '8', before: 'd', after: 'e' }, - { id: '9', after: 'c', group: 'a' } - ]; + it('sorts dependencies (explicit)', function (done) { + + var set = '0123456789abcdefghijklmnopqrstuvwxyz'; + var array = set.split(''); + + var scenario = []; + for (var i = 0, il = array.length; i < il; ++i) { + var item = { + id: array[i], + group: array[i], + after: i ? array.slice(0, i) : [], + before: array.slice(i + 1) + }; + scenario.push(item); + } + + var fisherYates = function (array) { + + var i = array.length; + while (--i) { + var j = Math.floor(Math.random() * (i + 1)); + var tempi = array[i]; + var tempj = array[j]; + array[i] = tempj; + array[j] = tempi; + } + }; + fisherYates(scenario); testDeps(scenario, function (result) { - expect(result).to.equal('0213547869'); + expect(result).to.equal(set); done(); }); }); + + it('throws on circular dependency', function (done) { + + var scenario = [ + { id: '0', before: 'a', group: 'b'}, + { id: '1', before: 'c', group: 'a' }, + { id: '2', before: 'b', group: 'c' } + ]; + + expect(function () { + + testDeps(scenario, function (result) { }); + }).to.throw(); + + done(); + }); }); }); \ No newline at end of file