diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/configuration.js | 8 | ||||
-rw-r--r-- | test/ebook.js | 19 | ||||
-rw-r--r-- | test/plugins.js | 7 | ||||
-rw-r--r-- | test/resolve.js | 61 |
4 files changed, 90 insertions, 5 deletions
diff --git a/test/configuration.js b/test/configuration.js index eedec49..2cff26e 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -29,4 +29,12 @@ describe('Configuration', function () { book.options.title.should.be.equal("js-config"); }); }); + + it('should provide configuration on book.config.get', function() { + return books.parse("basic") + .then(function(book) { + book.config.get('description').should.be.equal("Default description for the book."); + book.getConfig('description').should.be.equal("Default description for the book."); + }); + }); }); diff --git a/test/ebook.js b/test/ebook.js index 9b353d2..033fd04 100644 --- a/test/ebook.js +++ b/test/ebook.js @@ -37,12 +37,23 @@ describe('eBook generator', function () { path.join(book.options.output, "index.html"), { encoding: "utf-8" } ); + + // There are 2 styles (one from plugin-highlight and the new style) PAGE.should.be.html({ "link": { - count: 1, - attributes: { - href: "./styles/print.css" - } + count: 2 + } + }); + + PAGE.should.be.html({ + "link[href='./styles/print.css']": { + count: 1 + } + }); + + PAGE.should.be.html({ + "link[href='gitbook/plugins/gitbook-plugin-highlight/ebook.css']": { + count: 1 } }); }); diff --git a/test/plugins.js b/test/plugins.js index cc9c8e6..6d5b9de 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -90,7 +90,12 @@ describe('Plugins', function () { it('should extend books plugins', function() { var resources = book.plugins.resources("ebook"); - resources["css"].should.have.lengthOf(1); + + // There is resources from highlight plugin and this plugin + resources["css"].should.have.lengthOf(2); + should.exist(_.find(resources["css"], { + path: './resources/test' + })); }); }); }); diff --git a/test/resolve.js b/test/resolve.js new file mode 100644 index 0000000..b31a10d --- /dev/null +++ b/test/resolve.js @@ -0,0 +1,61 @@ +var fs = require('fs'); +var path = require('path'); + +describe('Resolve Files', function () { + var book; + + before(function() { + return books.parse("basic") + .then(function(_book) { + book = _book; + }); + }); + + describe('book.fileIsInBook', function() { + it('should return true for correct paths', function() { + book.fileIsInBook(path.join(book.root, 'README.md')).should.equal(true); + book.fileIsInBook(path.join(book.root, 'styles/website.css')).should.equal(true); + }); + + it('should return true for root folder', function() { + book.fileIsInBook(path.join(book.root, './')).should.equal(true); + book.fileIsInBook(book.root).should.equal(true); + }); + + it('should return false for files out of scope', function() { + book.fileIsInBook(path.join(book.root, '../')).should.equal(false); + book.fileIsInBook('README.md').should.equal(false); + book.fileIsInBook(path.resolve(book.root, '../README.md')).should.equal(false); + }); + + it('should correctly handle windows paths', function() { + book.fileIsInBook(path.join(book.root, '\\styles\\website.css')).should.equal(true); + }); + }); + + describe('book.resolve', function() { + it('should resolve a file to its absolute path', function() { + book.resolve('README.md').should.equal(path.resolve(book.root, 'README.md')); + book.resolve('website/README.md').should.equal(path.resolve(book.root, 'website/README.md')); + }); + + it('should correctly handle windows paths', function() { + book.resolve('styles\\website.css').should.equal(path.resolve(book.root, 'styles\\website.css')); + }); + + it('should correctly resolve all arguments', function() { + book.resolve('test', 'hello', '..', 'README.md').should.equal(path.resolve(book.root, 'test/README.md')); + }); + + it('should correctly resolve to root folder', function() { + book.resolve('test', '/README.md').should.equal(path.resolve(book.root, 'README.md')); + book.resolve('test', '\\README.md').should.equal(path.resolve(book.root, 'README.md')); + }); + + it('should throw an error for file out of book', function() { + (function() { + return book.resolve('../README.md'); + }).should.throw(); + }); + }); +}); |