summaryrefslogtreecommitdiffstats
path: root/test/json.js
blob: d7f6aac7fa77f33c4eeac890e438740c3c4bf1c1 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var path = require('path');
var _ = require('lodash');
var assert = require('assert');

var fs = require("fs");

describe('JSON generator', function () {
    it('should correctly generate a book to json with glossary', function(done) {
        testGeneration(books[0], "json", function(output) {
            assert(fs.existsSync(path.join(output, "README.json")));

            var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
            assert(readme.sections[0].content.indexOf('class="glossary-term"') > 0);
        }, done);
    });

    it('should correctly generate a book to json with sub folders', function(done) {
        testGeneration(books[1], "json", function(output) {
            assert(fs.existsSync(path.join(output, "README.json")));
            assert(fs.existsSync(path.join(output, "intro.json")));
            assert(fs.existsSync(path.join(output, "sub/test1.json")));

            var test1 = JSON.parse(fs.readFileSync(path.join(output, "sub/test1.json")));
            assert(test1.sections[0].content.indexOf("index.html") > 0);
        }, done);
    });

    it('should correctly generate a multilingual book to json', function(done) {
        testGeneration(books[2], "json", function(output) {
            assert(fs.existsSync(path.join(output, "README.json")));
            assert(fs.existsSync(path.join(output, "en/README.json")));
            assert(fs.existsSync(path.join(output, "fr/README.json")));
        }, done);
    });

    it('should correctly generate an asciidoc book to json', function(done) {
        testGeneration(books[3], "json", function(output) {
            assert(fs.existsSync(path.join(output, "README.json")));
            assert(fs.existsSync(path.join(output, "test.json")));
            assert(fs.existsSync(path.join(output, "test1.json")));
            assert(fs.existsSync(path.join(output, "test2.json")));
        }, done);
    });

    it('should correctly generate a book with local inclusion', function(done) {
        testGeneration(books[5], "json", function(output) {
            var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
            assert(readme.sections[0].content.indexOf('Hello World') > 0);
        }, done);
    });

    it('should correctly generate a book with external inclusion', function(done) {
        testGeneration(books[5], "json", function(output) {
            var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
            assert(readme.sections[0].content.indexOf('Git1:Hello from git') > 0);
            assert(readme.sections[0].content.indexOf('Git2:First Hello. Hello from git') > 0);
        }, done);
    });
});