diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-03-24 23:14:17 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-03-24 23:14:17 +0100 |
commit | c9af209a9335ea1219c3149eb12c2daa271c9403 (patch) | |
tree | 72df3edf7a67db465ce2dacbbf204974253b818a /test/images.js | |
parent | 63ee94ff89d10e56d82079183c494f8129b92eae (diff) | |
parent | 48ab44a776b665b1d3627192cf82e9220ec74678 (diff) | |
download | gitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.zip gitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.tar.gz gitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.tar.bz2 |
Merge pull request #667 from GitbookIO/better-testing
Better Unit Tests
Diffstat (limited to 'test/images.js')
-rw-r--r-- | test/images.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/images.js b/test/images.js new file mode 100644 index 0000000..75bc529 --- /dev/null +++ b/test/images.js @@ -0,0 +1,56 @@ +var fs = require('fs'); +var _ = require('lodash'); +var path = require('path'); +var cheerio = require('cheerio'); + +describe('Images', function () { + var book, readme, $, $img, srcs; + + before(function() { + return books.generate("images", "ebook") + .then(function(_book) { + book = _book; + + readme = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + $ = cheerio.load(readme); + $img = $("img"); + srcs = $img.map(function() { return $(this).attr("src"); }) + }); + }); + + it('should detect all images', function() { + _.uniq(srcs).should.have.lengthOf(4); + }); + + it('should keep image tags', function() { + srcs.should.have.lengthOf(5); + }); + + it('should not have .svg files', function() { + _.each(srcs, function(src) { + path.extname(src).should.not.equal(".svg"); + }); + }); + + it('should correctly convert svg images to png', function() { + _.each(srcs, function(src) { + book.should.have.file(src); + }); + }); + + it('should handle relative paths', function() { + var PAGE = fs.readFileSync( + path.join(book.options.output, "folder/PAGE.html"), + { encoding: "utf-8" } + ); + + PAGE.should.be.html({ + "img[src='../test.png']": { + count: 1 + } + }); + }); +}); |