summaryrefslogtreecommitdiffstats
path: root/test/assets-inliner.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-13 15:28:07 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-13 15:28:07 +0100
commitee3faaad1106bb773078e580c9c1611c8f31607c (patch)
tree5a6298dd565290e1776caec97f5ee9f42c65dd51 /test/assets-inliner.js
parentd2aad34935cb243dcdaeabfc28dce150c68f6340 (diff)
downloadgitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.zip
gitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.tar.gz
gitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.tar.bz2
Complete assets inliner
Diffstat (limited to 'test/assets-inliner.js')
-rw-r--r--test/assets-inliner.js82
1 files changed, 48 insertions, 34 deletions
diff --git a/test/assets-inliner.js b/test/assets-inliner.js
index 76b04f6..1f00b5d 100644
--- a/test/assets-inliner.js
+++ b/test/assets-inliner.js
@@ -1,56 +1,70 @@
var cheerio = require('cheerio');
+var path = require('path');
var mock = require('./mock');
var AssetsInliner = require('../lib/output/assets-inliner');
describe('Assets Inliner Output', function() {
+ var output;
- describe('SVG', function() {
- var output;
-
- before(function() {
- var SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>';
-
- return mock.outputDefaultBook(AssetsInliner, {
- 'README.md': '![image](test.svg)',
- 'inline.md': 'This is a svg: '+SVG,
- 'test.svg': '<?xml version="1.0" encoding="UTF-8"?>' + SVG,
- 'SUMMARY.md': '* [inline](inline.md)\n\n'
- })
- .then(function(_output) {
- output = _output;
- });
- });
+ before(function() {
+ var SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>';
+
+ return mock.outputDefaultBook(AssetsInliner, {
+ 'README.md': '',
- it('should correctly SVG files convert to PNG', function() {
- var page = output.book.getPage('README.md');
- var $ = cheerio.load(page.content);
+ // test for SVGS
+ 'svg_file.md': '![image](test.svg)',
+ 'svg_inline.md': 'This is a svg: '+SVG,
+ 'test.svg': '<?xml version="1.0" encoding="UTF-8"?>' + SVG,
- // Is there an image?
- var $img = $('img');
- $img.length.should.equal(1);
+ // test for remote files
+ 'remote_png.md': '![image](https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png)',
+ 'remote_svg.md': '![image](https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg)',
- // Does the file exists
- var src = $img.attr('src');
- output.should.have.file(src);
+ 'SUMMARY.md': '* [svg inline](svg_inline.md)\n' +
+ '* [svg file](svg_file.md)\n' +
+ '* [remote png file](remote_png.md)\n' +
+ '* [remote svg file](remote_svg.md)\n' +
+ '\n\n'
+ })
+ .then(function(_output) {
+ output = _output;
});
+ });
+
+ function testImageInPage(filename) {
+ var page = output.book.getPage(filename);
+ var $ = cheerio.load(page.content);
- it('should correctly inline SVG convert to PNG', function() {
- var page = output.book.getPage('inline.md');
- var $ = cheerio.load(page.content);
+ // Is there an image?
+ var $img = $('img');
+ $img.length.should.equal(1);
- // Is there an image?
- var $img = $('img');
- $img.length.should.equal(1);
+ // Does the file exists
+ var src = $img.attr('src');
+ output.should.have.file(src);
+ path.extname(src).should.equal('.png');
+ }
- // Does the file exists
- var src = $img.attr('src');
- output.should.have.file(src);
+ describe('SVG', function() {
+ it('should correctly convert SVG files to PNG', function() {
+ testImageInPage('svg_file.md');
+ });
+
+ it('should correctly convert inline SVG to PNG', function() {
+ testImageInPage('svg_inline.md');
});
});
describe('Remote Assets', function() {
+ it('should correctly download a PNG file', function() {
+ testImageInPage('remote_png.md');
+ });
+ it('should correctly download then convert a remote SVG to PNG', function() {
+ testImageInPage('remote_svg.md');
+ });
});
});