summaryrefslogtreecommitdiffstats
path: root/lib/templating/__tests__/conrefsLoader.js
blob: a6a89bae1ffdd279a40c69798bc24001ec490eed (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
var path = require('path');

var TemplateEngine = require('../../models/templateEngine');
var renderTemplate = require('../render');
var ConrefsLoader = require('../conrefsLoader');

describe('ConrefsLoader', function() {
    var dirName = __dirname + '/';
    var fileName = path.join(dirName, 'test.md');

    console.log(dirName);
    describe('Git', function() {
        var engine = TemplateEngine({
            loader: new ConrefsLoader(dirName)
        });

        it('should include content from git', function() {
            return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
            .then(function(out) {
                expect(out.getContent()).toBe('Hello from git');
            });
        });

        it('should handle deep inclusion (1)', function() {
            return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
            .then(function(out) {
                expect(out.getContent()).toBe('First Hello. Hello from git');
            });
        });

        it('should handle deep inclusion (2)', function() {
            return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
            .then(function(out) {
                expect(out.getContent()).toBe('First Hello. Hello from git');
            });
        });
    });

    describe('transform', function() {
        function transform(filePath, source) {
            return 'test-' + source + '-endtest';
        }
        var engine = TemplateEngine({
            loader: new ConrefsLoader(dirName, transform)
        });

        it('should transform included content', function() {
            return renderTemplate(engine, fileName, '{% include "include.md" %}')
            .then(function(out) {
                expect(out.getContent()).toBe('test-Hello World-endtest');
            });
        });
    });
});