diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-21 22:51:59 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-21 22:51:59 +0100 |
commit | 85930161f7a32c6c5c7de82a47554ed2855c14df (patch) | |
tree | 5c784ec80b59dd71867527d1658b1b5186b73a1e /test/helper.js | |
parent | 4f9ece1ec114901d817c77e584b933f195ece923 (diff) | |
download | gitbook-85930161f7a32c6c5c7de82a47554ed2855c14df.zip gitbook-85930161f7a32c6c5c7de82a47554ed2855c14df.tar.gz gitbook-85930161f7a32c6c5c7de82a47554ed2855c14df.tar.bz2 |
Normalize tests
Diffstat (limited to 'test/helper.js')
-rw-r--r-- | test/helper.js | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/test/helper.js b/test/helper.js index f29b3c7..27d5f01 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,5 +1,8 @@ var path = require('path'); var Q = require('q'); +var fs = require('fs'); +var _ = require('lodash'); + var Book = require('../').Book; // Nicety for mocha / Q @@ -11,20 +14,28 @@ global.qdone = function qdone(promise, done) { }).done(); }; +// Books for testings +global.books = []; + // Init before doing tests before(function(done) { - global.book1 = new Book(path.join(__dirname, './fixtures/test1')); - global.book2 = new Book(path.join(__dirname, './fixtures/test2')); - global.book3 = new Book(path.join(__dirname, './fixtures/test3')); + var books = fs.readdirSync(path.join(__dirname, './fixtures/')); + + global.books = _.chain(books) + .sortBy() + .map(function(book) { + if (book.indexOf("test") !== 0) return null; + return new Book(path.join(__dirname, './fixtures/', book));; + }) + .compact() + .value(); qdone( - global.book1.parse() - .then(function() { - return global.book2.parse(); - }) - .then(function() { - return global.book3.parse(); - }), + _.reduce(global.books, function(prev, book) { + return prev.then(function() { + return book.parse(); + }); + }, Q()), done ); }); |