summaryrefslogtreecommitdiffstats
path: root/test/helper.js
blob: 27d5f01e19a43d92f0fdce6599b99f410ed0df2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var path = require('path');
var Q = require('q');
var fs = require('fs');
var _ = require('lodash');

var Book = require('../').Book;

// Nicety for mocha / Q
global.qdone = function qdone(promise, done) {
    return promise.then(function() {
        return done();
    }, function(err) {
        return done(err);
    }).done();
};

// Books for testings
global.books = [];

// Init before doing tests
before(function(done) {
    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(
	    _.reduce(global.books, function(prev, book) {
            return prev.then(function() {
                return book.parse();
            });
        }, Q()),
	    done
	);
});