diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-02-12 11:40:17 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-02-12 11:40:17 +0100 |
commit | d9da4e9a08e8550031f46ec30b0cdbdffe395eee (patch) | |
tree | 29b7bb18dfda6c6d2d06622a58e8a1ae34faf48f /test/ebook.js | |
parent | 1d0f6370add0f57f3c549826eb87a313b7df33cc (diff) | |
download | gitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.zip gitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.tar.gz gitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.tar.bz2 |
Fix GitbookIO/plugin-youtube#2: hash remote image for local path
Diffstat (limited to 'test/ebook.js')
-rw-r--r-- | test/ebook.js | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/test/ebook.js b/test/ebook.js index 9432afa..c3e29d9 100644 --- a/test/ebook.js +++ b/test/ebook.js @@ -1,6 +1,7 @@ var path = require('path'); var _ = require('lodash'); var assert = require('assert'); +var cheerio = require('cheerio'); var fs = require("fs"); var fsUtil = require("../lib/utils/fs"); @@ -15,26 +16,22 @@ describe('eBook Generator', function () { it('should correctly convert svg images to png', function(done) { testGeneration(books[4], "ebook", function(output) { - var readmeContent = fs.readFileSync(path.join(output, "index.html"), {encoding: "utf8"}); - var pageContent = fs.readFileSync(path.join(output, "sub/PAGE.html"), {encoding: "utf8"}); - - // Remote image - assert(pageContent.indexOf('src="../Tux.png"') >= 0); - assert(fs.existsSync(path.join(output, "Tux.png"))); - - assert(fs.existsSync(path.join(output, "test.png"))); - assert(fs.existsSync(path.join(output, "NewTux.png"))); - - assert(!fs.existsSync(path.join(output, "test_0.png"))); - assert(!fs.existsSync(path.join(output, "sub/test.png"))); - assert(!fs.existsSync(path.join(output, "sub/NewTux.png"))); - - assert(pageContent.indexOf('src="../test.png"') >= 0); - assert(pageContent.indexOf('src="../NewTux.png"') >= 0); - assert(pageContent.indexOf('<svg') < 0); - - assert(readmeContent.indexOf('src="test.png"') >= 0); - assert(readmeContent.indexOf('src="NewTux.png"') >= 0); + // Check that all images exists + _.each([ + "index.html", + "sub/PAGE.html" + ], function(pageName) { + var pageFile = path.join(output, pageName); + var pageFolder = path.dirname(pageFile); + var pageContent = fs.readFileSync(pageFile, {encoding: "utf8"}); + var $ = cheerio.load(pageContent); + + $("img").each(function() { + var src = $(this).attr("src"); + console.log(path.resolve(pageFolder, src)); + assert(fs.existsSync(path.resolve(pageFolder, src)), src+" not found for page "+pageName); + }) + }); }, done); }); }); |