diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/IMAGES.md | 12 | ||||
-rw-r--r-- | test/page.js | 34 | ||||
-rw-r--r-- | test/plugin.js | 49 |
3 files changed, 91 insertions, 4 deletions
diff --git a/test/fixtures/IMAGES.md b/test/fixtures/IMAGES.md new file mode 100644 index 0000000..99ffa00 --- /dev/null +++ b/test/fixtures/IMAGES.md @@ -0,0 +1,12 @@ +# Images Test + +This is a test for images path calculation. It supposed this fiel is in a syntax/ folder + +### # + +[](./preview.png) + +### 2 + +[](./preview2.png) + diff --git a/test/page.js b/test/page.js index 52a3df6..fb6fd70 100644 --- a/test/page.js +++ b/test/page.js @@ -36,10 +36,6 @@ describe('Page parsing', function() { assert(LEXED[2].content); }); - it('should make image URLs relative', function() { - assert(LEXED[2].content.indexOf('_book/assets/my-pretty-picture.png') !== -1); - }); - it('should gen code and content for exercise sections', function() { assert(LEXED[1].content); assert(LEXED[1].code); @@ -94,3 +90,33 @@ describe('Relative links', function() { assert(LEXED[0].content.indexOf('https://github.com/GitBookIO/javascript/blob/src/something.cpp') !== -1); }); }); + +describe('Relative images', function() { + it('should keep image relative with considering output directory in site format', function() { + var LEXED = loadPage('IMAGES', { + // GitHub repo ID + repo: 'GitBookIO/javascript', + + // Imaginary folder of markdown file + dir: 'syntax', + outdir: 'syntax' + }); + + assert(LEXED[0].content.indexOf('"preview.png"') !== -1); + assert(LEXED[0].content.indexOf('"../preview2.png"') !== -1); + }); + + it('should keep image relative with considering output directory in page format', function() { + var LEXED = loadPage('IMAGES', { + // GitHub repo ID + repo: 'GitBookIO/javascript', + + // Imaginary folder of markdown file + dir: 'syntax', + outdir: './' + }); + + assert(LEXED[0].content.indexOf('"syntax/preview.png"') !== -1); + assert(LEXED[0].content.indexOf('"preview2.png"') !== -1); + }); +}); diff --git a/test/plugin.js b/test/plugin.js new file mode 100644 index 0000000..518ea3c --- /dev/null +++ b/test/plugin.js @@ -0,0 +1,49 @@ +var _ = require('lodash'); +var path = require('path'); +var assert = require('assert'); + +var Plugin = require('../').generate.Plugin; + +describe('Plugin validation', function () { + var plugin = new Plugin("gitbook-plugin"); + + it('should be valid', function() { + assert(plugin.isValid()); + }); +}); + +describe('Plugin list of names', function () { + var firstDefault = _.first(Plugin.defaults); + + it('should convert string to array', function() { + var _name = "test"; + assert(_.contains(Plugin.normalizeNames(_name), _name)); + }); + + it('should contains default plugins', function() { + assert(_.contains(Plugin.normalizeNames([]), firstDefault)); + }); + + it('should remove name starting with -', function() { + assert(!_.contains(Plugin.normalizeNames(["-"+firstDefault]), firstDefault)); + }); +}); + +describe('Plugin defaults loading', function () { + var ret = true; + + beforeEach(function(done){ + Plugin.fromList(Plugin.defaults) + .then(function(_r) { + ret = _r; + }, function(err) { + ret = null; + }) + .fin(done); + }); + + + it('should load defaults addons', function() { + assert(ret != null); + }); +}); |