summaryrefslogtreecommitdiffstats
path: root/lib/templating/__tests__/conrefsLoader.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-11 15:08:10 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-11 15:08:10 +0200
commit9013f02850d7e4cc934eb75967b5f976030e2f0d (patch)
tree5b17b82bd519d5b4250df09bc3f881cb6b3d5d5c /lib/templating/__tests__/conrefsLoader.js
parent961d43f085036263edfe064c2107ab27ad62d8fa (diff)
downloadgitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.zip
gitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.tar.gz
gitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.tar.bz2
Add test for transform option of ConrefLoader
Diffstat (limited to 'lib/templating/__tests__/conrefsLoader.js')
-rw-r--r--lib/templating/__tests__/conrefsLoader.js37
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/templating/__tests__/conrefsLoader.js b/lib/templating/__tests__/conrefsLoader.js
index d430a4f..a6a89ba 100644
--- a/lib/templating/__tests__/conrefsLoader.js
+++ b/lib/templating/__tests__/conrefsLoader.js
@@ -1,34 +1,55 @@
+var path = require('path');
+
var TemplateEngine = require('../../models/templateEngine');
var renderTemplate = require('../render');
+var ConrefsLoader = require('../conrefsLoader');
describe('ConrefsLoader', function() {
- var ConrefsLoader = require('../conrefsLoader');
-
- var engine = TemplateEngine({
- loader: new ConrefsLoader(__dirname)
- });
+ 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, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
+ 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, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
+ 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, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
+ 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');
+ });
+ });
+ });
});