summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/books/basic/README.md1
-rw-r--r--test/books/basic/SUMMARY.md (renamed from test/fixtures/test2/en/SUMMARY.md)0
-rw-r--r--test/books/basic/_book/README.json31
-rw-r--r--test/configuration.js14
-rw-r--r--test/ebook.js36
-rw-r--r--test/fixtures/test0/GLOSSARY.md6
-rw-r--r--test/fixtures/test0/README.md3
-rw-r--r--test/fixtures/test0/SUMMARY.md1
-rw-r--r--test/fixtures/test0/book.json3
-rw-r--r--test/fixtures/test0/styles/website.css3
-rw-r--r--test/fixtures/test1/GLOSSARY.md9
-rw-r--r--test/fixtures/test1/README.md4
-rw-r--r--test/fixtures/test1/SUMMARY.md6
-rw-r--r--test/fixtures/test1/book.json5
-rw-r--r--test/fixtures/test1/intro.md4
-rw-r--r--test/fixtures/test1/sub/test1.md8
-rw-r--r--test/fixtures/test2/LANGS.md4
-rw-r--r--test/fixtures/test2/README.md2
-rw-r--r--test/fixtures/test2/en/README.md1
-rw-r--r--test/fixtures/test2/fr/README.md1
-rw-r--r--test/fixtures/test2/fr/SUMMARY.md1
-rw-r--r--test/fixtures/test3/README.adoc4
-rw-r--r--test/fixtures/test3/SUMMARY.adoc5
-rw-r--r--test/fixtures/test3/test.adoc0
-rw-r--r--test/fixtures/test3/test1.adoc0
-rw-r--r--test/fixtures/test3/test2.adoc0
-rw-r--r--test/fixtures/test4/README.md11
-rw-r--r--test/fixtures/test4/SUMMARY.md3
-rw-r--r--test/fixtures/test4/book.js3
-rw-r--r--test/fixtures/test4/sub/PAGE.md18
-rw-r--r--test/fixtures/test4/test.svg11
-rw-r--r--test/fixtures/test5/README.md5
-rw-r--r--test/fixtures/test5/SUMMARY.md1
-rw-r--r--test/fixtures/test5/test.md1
-rw-r--r--test/git.js32
-rw-r--r--test/glossary.js35
-rw-r--r--test/helper.js97
-rw-r--r--test/json.js59
-rw-r--r--test/links.js40
-rw-r--r--test/parsing.js82
-rw-r--r--test/plugins.js189
-rw-r--r--test/plugins/blocks/index.js41
-rw-r--r--test/plugins/blocks/package.json9
-rw-r--r--test/plugins/empty/index.js1
-rw-r--r--test/plugins/empty/package.json9
-rw-r--r--test/plugins/filters/index.js10
-rw-r--r--test/plugins/filters/package.json9
-rw-r--r--test/plugins/invalid/index.js1
-rw-r--r--test/plugins/invalid/package.json9
-rw-r--r--test/plugins/resources/index.js12
-rw-r--r--test/plugins/resources/package.json9
-rw-r--r--test/templating.js37
-rw-r--r--test/website.js40
53 files changed, 89 insertions, 837 deletions
diff --git a/test/books/basic/README.md b/test/books/basic/README.md
new file mode 100644
index 0000000..f395431
--- /dev/null
+++ b/test/books/basic/README.md
@@ -0,0 +1 @@
+# Readme
diff --git a/test/fixtures/test2/en/SUMMARY.md b/test/books/basic/SUMMARY.md
index ac9323c..ac9323c 100644
--- a/test/fixtures/test2/en/SUMMARY.md
+++ b/test/books/basic/SUMMARY.md
diff --git a/test/books/basic/_book/README.json b/test/books/basic/_book/README.json
new file mode 100644
index 0000000..13dae6b
--- /dev/null
+++ b/test/books/basic/_book/README.json
@@ -0,0 +1,31 @@
+{
+ "progress": {
+ "prevPercent": 0,
+ "percent": 0,
+ "chapters": [
+ {
+ "index": 0,
+ "title": "",
+ "level": "0",
+ "path": "README.md",
+ "percent": 0,
+ "done": true
+ }
+ ],
+ "current": {
+ "index": 0,
+ "title": "",
+ "level": "0",
+ "path": "README.md",
+ "percent": 0,
+ "done": true
+ }
+ },
+ "sections": [
+ {
+ "type": "normal",
+ "content": "<h1 id=\"readme\">Readme</h1>\n"
+ }
+ ],
+ "langs": []
+} \ No newline at end of file
diff --git a/test/configuration.js b/test/configuration.js
deleted file mode 100644
index e690f2c..0000000
--- a/test/configuration.js
+++ /dev/null
@@ -1,14 +0,0 @@
-var path = require('path');
-var assert = require('assert');
-
-var Book = require('../').Book;
-
-describe('Configuration parsing', function () {
- it('should correctly load from json', function() {
- assert(books[0].options.title == "Test");
- });
-
- it('should correctly load from javascript', function() {
- assert(books[4].options.title == "Test 2");
- });
-});
diff --git a/test/ebook.js b/test/ebook.js
deleted file mode 100644
index d02e7cd..0000000
--- a/test/ebook.js
+++ /dev/null
@@ -1,36 +0,0 @@
-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");
-
-
-describe('eBook Generator', function () {
- it('should correctly generate ebook pages', function(done) {
- testGeneration(books[1], "ebook", function(output) {
- assert(fs.existsSync(path.join(output, "SUMMARY.html")));
- }, done);
- });
-
- it('should correctly convert svg images to png', function(done) {
- testGeneration(books[4], "ebook", function(output) {
- // 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");
- assert(fs.existsSync(path.resolve(pageFolder, src)), src+" not found for page "+pageName);
- })
- });
- }, done);
- });
-});
diff --git a/test/fixtures/test0/GLOSSARY.md b/test/fixtures/test0/GLOSSARY.md
deleted file mode 100644
index ad07f86..0000000
--- a/test/fixtures/test0/GLOSSARY.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# Glossary
-
-## Description
-
-This is the dexcription of a description.
-
diff --git a/test/fixtures/test0/README.md b/test/fixtures/test0/README.md
deleted file mode 100644
index a2fdfea..0000000
--- a/test/fixtures/test0/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Other Title
-
-This is a description, it's simple, no ?
diff --git a/test/fixtures/test0/SUMMARY.md b/test/fixtures/test0/SUMMARY.md
deleted file mode 100644
index 27870e5..0000000
--- a/test/fixtures/test0/SUMMARY.md
+++ /dev/null
@@ -1 +0,0 @@
-# Summary \ No newline at end of file
diff --git a/test/fixtures/test0/book.json b/test/fixtures/test0/book.json
deleted file mode 100644
index 41faa63..0000000
--- a/test/fixtures/test0/book.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "title": "Test"
-} \ No newline at end of file
diff --git a/test/fixtures/test0/styles/website.css b/test/fixtures/test0/styles/website.css
deleted file mode 100644
index 5c5e887..0000000
--- a/test/fixtures/test0/styles/website.css
+++ /dev/null
@@ -1,3 +0,0 @@
-body {
- background: red;
-}
diff --git a/test/fixtures/test1/GLOSSARY.md b/test/fixtures/test1/GLOSSARY.md
deleted file mode 100644
index dc14550..0000000
--- a/test/fixtures/test1/GLOSSARY.md
+++ /dev/null
@@ -1,9 +0,0 @@
-
-# Test
-
-a test text
-
-# Test 2
-
-a second test
-
diff --git a/test/fixtures/test1/README.md b/test/fixtures/test1/README.md
deleted file mode 100644
index 2f7a8d4..0000000
--- a/test/fixtures/test1/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Test
-
-This file is not parsed by gitbook because the structure is defined in book.json.
-
diff --git a/test/fixtures/test1/SUMMARY.md b/test/fixtures/test1/SUMMARY.md
deleted file mode 100644
index d05fc4a..0000000
--- a/test/fixtures/test1/SUMMARY.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# Summary
-
-* [Chapter 1](test.md)
- * [Article 1](sub/test1.md)
-* [Chapter 2](test2.md)
-* [Google](https://www.google.com)
diff --git a/test/fixtures/test1/book.json b/test/fixtures/test1/book.json
deleted file mode 100644
index edaa4fc..0000000
--- a/test/fixtures/test1/book.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "structure": {
- "readme": "intro.md"
- }
-} \ No newline at end of file
diff --git a/test/fixtures/test1/intro.md b/test/fixtures/test1/intro.md
deleted file mode 100644
index bf9a1cf..0000000
--- a/test/fixtures/test1/intro.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# My Book
-
-Test description
-
diff --git a/test/fixtures/test1/sub/test1.md b/test/fixtures/test1/sub/test1.md
deleted file mode 100644
index d45a4dd..0000000
--- a/test/fixtures/test1/sub/test1.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# This file is used to etst links transformations:
-
-This is a relative link [test](../intro.md).
-
-![image](../image.png)
-
-This is a glossary link.
-
diff --git a/test/fixtures/test2/LANGS.md b/test/fixtures/test2/LANGS.md
deleted file mode 100644
index a501d22..0000000
--- a/test/fixtures/test2/LANGS.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Languages
-
-* [English](en/)
-* [French](fr/)
diff --git a/test/fixtures/test2/README.md b/test/fixtures/test2/README.md
deleted file mode 100644
index c6186ac..0000000
--- a/test/fixtures/test2/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# Multi-Languages test
-
diff --git a/test/fixtures/test2/en/README.md b/test/fixtures/test2/en/README.md
deleted file mode 100644
index 95bc71c..0000000
--- a/test/fixtures/test2/en/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# English Book
diff --git a/test/fixtures/test2/fr/README.md b/test/fixtures/test2/fr/README.md
deleted file mode 100644
index c7a4103..0000000
--- a/test/fixtures/test2/fr/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# French Book
diff --git a/test/fixtures/test2/fr/SUMMARY.md b/test/fixtures/test2/fr/SUMMARY.md
deleted file mode 100644
index ac9323c..0000000
--- a/test/fixtures/test2/fr/SUMMARY.md
+++ /dev/null
@@ -1 +0,0 @@
-# Summary
diff --git a/test/fixtures/test3/README.adoc b/test/fixtures/test3/README.adoc
deleted file mode 100644
index ea295ee..0000000
--- a/test/fixtures/test3/README.adoc
+++ /dev/null
@@ -1,4 +0,0 @@
-= My Book
-
-Test description
-
diff --git a/test/fixtures/test3/SUMMARY.adoc b/test/fixtures/test3/SUMMARY.adoc
deleted file mode 100644
index 29fcb65..0000000
--- a/test/fixtures/test3/SUMMARY.adoc
+++ /dev/null
@@ -1,5 +0,0 @@
-= Summary
-
-. link:test.adoc[Chapter 1]
-.. link:test1.adoc[Article 1]
-. link:test2.adoc[Chapter 2]
diff --git a/test/fixtures/test3/test.adoc b/test/fixtures/test3/test.adoc
deleted file mode 100644
index e69de29..0000000
--- a/test/fixtures/test3/test.adoc
+++ /dev/null
diff --git a/test/fixtures/test3/test1.adoc b/test/fixtures/test3/test1.adoc
deleted file mode 100644
index e69de29..0000000
--- a/test/fixtures/test3/test1.adoc
+++ /dev/null
diff --git a/test/fixtures/test3/test2.adoc b/test/fixtures/test3/test2.adoc
deleted file mode 100644
index e69de29..0000000
--- a/test/fixtures/test3/test2.adoc
+++ /dev/null
diff --git a/test/fixtures/test4/README.md b/test/fixtures/test4/README.md
deleted file mode 100644
index d73be69..0000000
--- a/test/fixtures/test4/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-# Other Title
-
-A description
-
-![test image to be converted](./test.svg)
-![test url](http://upload.wikimedia.org/wikipedia/commons/b/b0/NewTux.svg)
-![test image to be converted, second use](./test.svg)
-
-# Test with youtube videos that have the same filename:
-![youtube1](http://img.youtube.com/vi/9bZkp7q19f0/0.jpg)
-![youtube2](http://img.youtube.com/vi/IkV2HQLAKHY/0.jpg)
diff --git a/test/fixtures/test4/SUMMARY.md b/test/fixtures/test4/SUMMARY.md
deleted file mode 100644
index 3cda114..0000000
--- a/test/fixtures/test4/SUMMARY.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Summary
-
-* [Page](sub/PAGE.md)
diff --git a/test/fixtures/test4/book.js b/test/fixtures/test4/book.js
deleted file mode 100644
index 4642b56..0000000
--- a/test/fixtures/test4/book.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- title: "Test 2"
-};
diff --git a/test/fixtures/test4/sub/PAGE.md b/test/fixtures/test4/sub/PAGE.md
deleted file mode 100644
index a98a942..0000000
--- a/test/fixtures/test4/sub/PAGE.md
+++ /dev/null
@@ -1,18 +0,0 @@
-##
-
-## Image from root page
-
-![test image to be converted](../test.svg)
-![test url](http://upload.wikimedia.org/wikipedia/commons/b/b0/NewTux.svg)
-
-## Inline svg
-
-{% html %}
-<svg xmlns="http://www.w3.org/2000/svg">
- <path d="M97.008198003228,6.103238498249268A97.2,97.2 0 0,1 87.9491894996971,41.385747140125076L54.289623147961166,25.546757493904366A60,60 0 0,0 59.88160370569629,3.7674311717588074Z"></path>
-</svg>
-{% endhtml %}
-
-## Remote image
-
-![remote url](http://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png)
diff --git a/test/fixtures/test4/test.svg b/test/fixtures/test4/test.svg
deleted file mode 100644
index 48bba70..0000000
--- a/test/fixtures/test4/test.svg
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
-<svg version="1.1" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg-root" width="100%" height="100%" viewBox="0 0 480 360">
- <title id="test-title">basic SVG tiny doc</title>
- <g id="test-body-content">
- <text font-family="Arial" font-size="14" text-anchor="middle" x="225" y="25">hello world</text>
- </g>
- <text id="revision" x="10" y="340" font-size="40" stroke="none" fill="black">Revision: 1.1</text>
- <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/>
-</svg>
-
diff --git a/test/fixtures/test5/README.md b/test/fixtures/test5/README.md
deleted file mode 100644
index 3db21b2..0000000
--- a/test/fixtures/test5/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Test Content inclusion
-
-{% include "./test.md" %}
-Git1:{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}
-Git2:{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %} \ No newline at end of file
diff --git a/test/fixtures/test5/SUMMARY.md b/test/fixtures/test5/SUMMARY.md
deleted file mode 100644
index ac9323c..0000000
--- a/test/fixtures/test5/SUMMARY.md
+++ /dev/null
@@ -1 +0,0 @@
-# Summary
diff --git a/test/fixtures/test5/test.md b/test/fixtures/test5/test.md
deleted file mode 100644
index 5e1c309..0000000
--- a/test/fixtures/test5/test.md
+++ /dev/null
@@ -1 +0,0 @@
-Hello World \ No newline at end of file
diff --git a/test/git.js b/test/git.js
deleted file mode 100644
index 9d48606..0000000
--- a/test/git.js
+++ /dev/null
@@ -1,32 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-
-var fs = require("fs");
-var git = require("../lib/utils/git");
-
-describe('GIT parser and getter', function () {
- it('should correctly parse an https url', function() {
- var parts = git.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md");
- assert(parts);
- assert.equal(parts.host, "https://gist.github.com/69ea4542e4c8967d2fa7.git");
- assert.equal(parts.ref, "master");
- assert.equal(parts.filepath, "test.md");
- });
-
- it('should correctly parse an https url with a reference', function() {
- var parts = git.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#0.1.2");
- assert(parts);
- assert.equal(parts.host, "https://gist.github.com/69ea4542e4c8967d2fa7.git");
- assert.equal(parts.ref, "0.1.2");
- assert.equal(parts.filepath, "test.md");
- });
-
- it('should correctly parse an ssh url', function() {
- var parts = git.parseUrl("git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
- assert(parts);
- assert.equal(parts.host, "git@github.com:GitbookIO/gitbook.git");
- assert.equal(parts.ref, "e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
- assert.equal(parts.filepath, "directory/README.md");
- });
-});
diff --git a/test/glossary.js b/test/glossary.js
deleted file mode 100644
index 5deb04c..0000000
--- a/test/glossary.js
+++ /dev/null
@@ -1,35 +0,0 @@
-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");
-
-
-describe('Glossary Generation', function () {
- it('should correctly replace glossary terms', function(done) {
- testGeneration(books[0], "website", function(output) {
- var content = fs.readFileSync(path.join(output, "index.html"), { encoding: "utf8" });
- var $ = cheerio.load(content);
-
- var $body = $(".page-inner");
- var $a = $("a[href='GLOSSARY.html#description']");
- assert($a.length == 1);
- assert($a.text() == "description");
- }, done);
- });
-
- it('should correctly replace glossary terms in sub pages', function(done) {
- testGeneration(books[1], "website", function(output) {
- var content = fs.readFileSync(path.join(output, "sub/test1.html"), { encoding: "utf8" });
- var $ = cheerio.load(content);
-
- var $body = $(".page-inner");
- var $a = $("a[href='../GLOSSARY.html#test']");
- assert($a.length == 1);
- assert($a.text() == "test");
- assert($a.attr("title") == "a test text");
- }, done);
- });
-});
diff --git a/test/helper.js b/test/helper.js
index 528d491..dfaaeb4 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -1,62 +1,71 @@
+var os = require('os');
var path = require('path');
var Q = require('q');
var fs = require('fs');
var _ = require('lodash');
+var should = require('should');
-var fsUtil = require("../lib/utils/fs");
+var fsUtil = require('../lib/utils/fs');
var Book = require('../').Book;
var LOG_LEVELS = require('../').LOG_LEVELS;
-// Nicety for mocha / Q
-global.qdone = function qdone(promise, done) {
- return promise.then(function() {
- return done();
- }, function(err) {
- return done(err);
- }).done();
-};
+var BOOKS = {};
+var TMPDIR = os.tmpdir();
-// Test generation of a book
-global.testGeneration = function(book, type, func, done) {
- var OUTPUT_PATH = book.options.output;
- qdone(
- book.generate(type)
- .then(function() {
- func(OUTPUT_PATH);
- })
- .fin(function() {
- return fsUtil.remove(OUTPUT_PATH);
- }),
- done);
-};
+// Generate and return a book
+function generateBook(bookId, test) {
+ BOOKS[bookId] = BOOKS[bookId] || {};
+ if (BOOKS[bookId][test]) return Q(BOOKS[bookId][test]);
-// Books for testings
-var books = fs.readdirSync(path.join(__dirname, './fixtures/'));
+ BOOKS[bookId][test] = new Book(path.resolve(__dirname, "books", bookId), {
+ logLevel: LOG_LEVELS.DISABLED,
+ output: path.resolve(TMPDIR, bookId+"-"+test)
+ });
-global.books = _.chain(books)
- .sortBy()
- .map(function(book) {
- if (book.indexOf("test") !== 0) return null;
- return new Book(path.join(__dirname, './fixtures/', book), {
- logLevel: LOG_LEVELS.DISABLED
- });
+ console.log("gen");
+ return BOOKS[bookId][test].parse()
+ .then(function() {
+ return BOOKS[bookId][test].generate(test);
})
- .compact()
- .value();
+ .then(function() {
+ return BOOKS[bookId][test];
+ });
+}
+
+// Generate and return a book
+function parseBook(bookId, test) {
+ BOOKS[bookId] = BOOKS[bookId] || {};
+ if (BOOKS[bookId][test]) return Q(BOOKS[book][test]);
+
+ BOOKS[bookId] = new Book(path.resolve(__dirname, "books", bookId), {
+ logLevel: LOG_LEVELS.DISABLED,
+ output: path.resolve(TMPDIR, bookId+"-"+test)
+ });
-// Init before doing tests
-before(function(done) {
+ return BOOKS[bookId].parse();
+}
- qdone(
- _.reduce(global.books, function(prev, book) {
+
+global.books = {
+ parse: parseBook,
+ generate: generateBook
+};
+
+// Cleanup all tests
+after(function() {
+ console.log("cleanup!");
+ return _.chain(BOOKS)
+ .map(function(types, bookId) {
+ return _.values(types);
+ })
+ .reduce(function(prev, book) {
return prev.then(function() {
- return fsUtil.remove(path.join(book.root, "_book"));
+ console.log("cleanup", book.options.output);
+ return fsUtil.remove(book.options.output);
})
- .then(function() {
- return book.parse();
- });
- }, Q()),
- done
- );
+ })
+ .value();
});
+
+
diff --git a/test/json.js b/test/json.js
index d7f6aac..82966a9 100644
--- a/test/json.js
+++ b/test/json.js
@@ -1,59 +1,8 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-
-var fs = require("fs");
describe('JSON generator', function () {
- it('should correctly generate a book to json with glossary', function(done) {
- testGeneration(books[0], "json", function(output) {
- assert(fs.existsSync(path.join(output, "README.json")));
-
- var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
- assert(readme.sections[0].content.indexOf('class="glossary-term"') > 0);
- }, done);
- });
-
- it('should correctly generate a book to json with sub folders', function(done) {
- testGeneration(books[1], "json", function(output) {
- assert(fs.existsSync(path.join(output, "README.json")));
- assert(fs.existsSync(path.join(output, "intro.json")));
- assert(fs.existsSync(path.join(output, "sub/test1.json")));
-
- var test1 = JSON.parse(fs.readFileSync(path.join(output, "sub/test1.json")));
- assert(test1.sections[0].content.indexOf("index.html") > 0);
- }, done);
- });
-
- it('should correctly generate a multilingual book to json', function(done) {
- testGeneration(books[2], "json", function(output) {
- assert(fs.existsSync(path.join(output, "README.json")));
- assert(fs.existsSync(path.join(output, "en/README.json")));
- assert(fs.existsSync(path.join(output, "fr/README.json")));
- }, done);
- });
-
- it('should correctly generate an asciidoc book to json', function(done) {
- testGeneration(books[3], "json", function(output) {
- assert(fs.existsSync(path.join(output, "README.json")));
- assert(fs.existsSync(path.join(output, "test.json")));
- assert(fs.existsSync(path.join(output, "test1.json")));
- assert(fs.existsSync(path.join(output, "test2.json")));
- }, done);
- });
-
- it('should correctly generate a book with local inclusion', function(done) {
- testGeneration(books[5], "json", function(output) {
- var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
- assert(readme.sections[0].content.indexOf('Hello World') > 0);
- }, done);
- });
-
- it('should correctly generate a book with external inclusion', function(done) {
- testGeneration(books[5], "json", function(output) {
- var readme = JSON.parse(fs.readFileSync(path.join(output, "README.json")));
- assert(readme.sections[0].content.indexOf('Git1:Hello from git') > 0);
- assert(readme.sections[0].content.indexOf('Git2:First Hello. Hello from git') > 0);
- }, done);
+ it('should correctly generate a basic book to json', function() {
+ return books.generate("basic", "json")
+ .then(function(book) {
+ });
});
});
diff --git a/test/links.js b/test/links.js
deleted file mode 100644
index 2c68a23..0000000
--- a/test/links.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-
-var links = require("../lib/utils/links");
-
-describe('Links', function () {
- it('should correctly test external links', function() {
- assert(links.isExternal("http://google.fr"));
- assert(links.isExternal("https://google.fr"));
- assert(!links.isExternal("test.md"));
- assert(!links.isExternal("folder/test.md"));
- assert(!links.isExternal("/folder/test.md"));
- });
-
- it('should correctly test anchor links', function() {
- assert(links.isAnchor("#test"));
- assert(links.isAnchor(" #test"));
- assert(!links.isAnchor("https://google.fr#test"));
- assert(!links.isAnchor("test.md#test"));
- });
-
- describe('toAbsolute', function() {
- it('should correctly transform as absolute', function() {
- assert.equal(links.toAbsolute("http://google.fr"), "http://google.fr");
- assert.equal(links.toAbsolute("test.md", "./", "./"), "test.md");
- assert.equal(links.toAbsolute("folder/test.md", "./", "./"), "folder/test.md");
- });
-
- it('should correctly handle windows path', function() {
- assert.equal(links.toAbsolute("folder\\test.md", "./", "./"), "folder/test.md");
- });
-
- it('should correctly handle absolute path', function() {
- assert.equal(links.toAbsolute("/test.md", "./", "./"), "test.md");
- assert.equal(links.toAbsolute("/test.md", "test", "test"), "../test.md");
- assert.equal(links.toAbsolute("/sub/test.md", "test", "test"), "../sub/test.md");
- });
- });
-});
diff --git a/test/parsing.js b/test/parsing.js
deleted file mode 100644
index 498de9f..0000000
--- a/test/parsing.js
+++ /dev/null
@@ -1,82 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-
-describe('Book parsing', function () {
- it('should correctly parse the readme', function() {
- assert.equal(books[1].options.title, 'My Book');
- assert.equal(books[1].options.description, 'Test description');
- });
-
- it('should correctly parse the readme with asciidoc', function() {
- assert.equal(books[3].options.title, 'My Book');
- assert.equal(books[3].options.description, 'Test description');
- });
-
- it('should correctly parse the summary', function() {
- var LEXED = books[1].summary;
-
- assert.equal(LEXED.chapters[0].path, 'intro.md');
- assert.equal(LEXED.chapters[0].exists, true);
- assert.equal(LEXED.chapters[0].introduction, true);
- assert.equal(LEXED.chapters[0].external, false);
-
- assert.equal(LEXED.chapters[1].path, 'test.md');
- assert.equal(LEXED.chapters[1].exists, false);
- assert.equal(LEXED.chapters[1].introduction, false);
- assert.equal(LEXED.chapters[1].external, false);
-
- assert.equal(LEXED.chapters[2].path, 'test2.md');
- assert.equal(LEXED.chapters[2].exists, false);
- assert.equal(LEXED.chapters[2].introduction, false);
- assert.equal(LEXED.chapters[2].external, false);
-
- assert.equal(LEXED.chapters[3].path, 'https://www.google.com');
- assert.equal(LEXED.chapters[3].exists, true);
- assert.equal(LEXED.chapters[3].introduction, false);
- assert.equal(LEXED.chapters[3].external, true);
- });
-
- it('should correctly parse the glossary', function() {
- var LEXED = books[1].glossary;
-
- assert.equal(LEXED[0].id, "test");
- assert.equal(LEXED[0].name, "Test");
- assert.equal(LEXED[0].description, "a test text");
-
- assert.equal(LEXED[1].id, "test_2");
- assert.equal(LEXED[1].name, "Test 2");
- assert.equal(LEXED[1].description, "a second test");
- });
-
- it('should correctly parse list of files', function() {
- var FILES = books[1].files;
-
- assert.deepEqual(FILES, [ 'README.md', 'intro.md', 'sub/', 'sub/test1.md' ]);
- });
-
- it('should correctly parse the languages', function() {
- assert.equal(books[2].books.length, 2);
- assert(books[2].isMultilingual());
-
- assert.equal(books[2].books[0].options.language, "en");
- assert.equal(books[2].books[0].options.title, "English Book");
-
- assert.equal(books[2].books[1].options.language, "fr");
- assert.equal(books[2].books[1].options.title, "French Book");
- });
-
- it('should correctly parse the navigation', function() {
- var NAVIGATION = books[1].navigation;
-
- assert.equal(_.size(NAVIGATION), 2);
- assert(NAVIGATION["intro.md"])
- assert.equal(NAVIGATION["intro.md"].title, "");
- assert.equal(NAVIGATION["intro.md"].prev, null);
- assert.equal(NAVIGATION["intro.md"].next.title, "Article 1");
-
- assert.equal(NAVIGATION["sub/test1.md"].title, "Article 1");
- assert.equal(NAVIGATION["sub/test1.md"].prev.title, "");
- assert.equal(NAVIGATION["sub/test1.md"].next, null);
- });
-});
diff --git a/test/plugins.js b/test/plugins.js
deleted file mode 100644
index c7d1f90..0000000
--- a/test/plugins.js
+++ /dev/null
@@ -1,189 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-var fs = require("fs");
-
-var Plugin = require("../lib/plugin");
-
-var PLUGINS_ROOT = path.resolve(__dirname, "plugins");
-
-describe('Plugins', function () {
- describe('invalid plugin', function() {
- it('should signal as invalid', function() {
- var plugin = new Plugin(books[0], "invalid");
- plugin.load("./invalid", PLUGINS_ROOT);
- assert(!plugin.isValid());
- });
- });
-
- describe('empty plugin', function() {
- var plugin = new Plugin(books[0], "invalid");
- plugin.load("./empty", PLUGINS_ROOT);
-
- it('should valid a plugin', function() {
- assert(plugin.isValid());
- });
-
- it('should return an empty list of resources', function(done) {
- qdone(
- plugin.getResources()
- .then(function(resources) {
- _.each(Plugin.RESOURCES, function(resName) {
- assert.equal(resources[resName].length, 0);
- });
- }),
- done);
- });
- });
-
- describe('resources plugin', function() {
- var plugin = new Plugin(books[0], "resources");
- plugin.load("./resources", PLUGINS_ROOT);
-
- before(function(done) {
- qdone(books[0].plugins.load(plugin), done);
- });
-
- it('should valid a plugin', function() {
- assert(plugin.isValid());
- });
-
- it('should return a valid list of resources (website)', function(done) {
- qdone(
- plugin.getResources("website")
- .then(function(resources) {
- assert.equal(resources["js"].length, 1);
- }),
- done);
- });
-
- it('should return a valid list of resources (ebook)', function(done) {
- qdone(
- plugin.getResources("ebook")
- .then(function(resources) {
- assert.equal(resources["css"].length, 1);
- }),
- done);
- });
-
- it('should extend books plugins (website)', function() {
- var resources = books[0].plugins.resources("website");
- assert.equal(resources["js"].length, 1);
- });
-
- it('should extend books plugins (ebook)', function() {
- var resources = books[0].plugins.resources("ebook");
- assert.equal(resources["css"].length, 1);
- });
- });
-
- describe('filters', function() {
- var plugin = new Plugin(books[0], "filters");
- plugin.load("./filters", PLUGINS_ROOT);
-
- before(function(done) {
- qdone(books[0].plugins.load(plugin), done);
- });
-
- it('should valid a plugin', function() {
- assert(plugin.isValid());
- });
-
- it('should return a map of filters', function() {
- var filters = plugin.getFilters();
- assert.equal(_.size(filters), 2);
- assert(filters["hello"]);
- assert(filters["helloCtx"]);
- });
-
- it('should correctly extend template filters', function(done) {
- qdone(
- books[0].template.renderString('{{ "World"|hello }}')
- .then(function(content) {
- assert.equal(content, "Hello World");
- }),
- done
- );
- });
-
- it('should correctly set book as context', function(done) {
- qdone(
- books[0].template.renderString('{{ "root"|helloCtx }}')
- .then(function(content) {
- assert.equal(content, "root:"+books[0].root);
- }),
- done
- );
- });
- });
-
- describe('blocks', function() {
- var plugin = new Plugin(books[0], "blocks");
- plugin.load("./blocks", PLUGINS_ROOT);
-
- var testTpl = function(str, args, options) {
- return books[0].template.renderString(str, args, options)
- .then(books[0].template.postProcess)
- };
-
- before(function(done) {
- qdone(books[0].plugins.load(plugin), done);
- });
-
- it('should valid a plugin', function() {
- assert(plugin.isValid());
- });
-
- it('should correctly extend template blocks', function(done) {
- qdone(
- testTpl('{% test %}hello{% endtest %}')
- .then(function(content) {
- assert.equal(content, "testhellotest");
- }),
- done
- );
- });
-
- it('should correctly accept shortcuts', function(done) {
- qdone(
- testTpl('$$hello$$', {}, {
- type: "markdown"
- })
- .then(function(content) {
- assert.equal(content, "testhellotest");
- }),
- done
- );
- });
-
- it('should correctly extend template blocks with defined end', function(done) {
- qdone(
- testTpl('{% test2 %}hello{% endtest2end %}')
- .then(function(content) {
- assert.equal(content, "test2hellotest2");
- }),
- done
- );
- });
-
- it('should correctly extend template blocks with sub-blocks', function(done) {
- qdone(
- testTpl('{% test3join separator=";" %}hello{% also %}world{% endtest3join %}')
- .then(function(content) {
- assert.equal(content, "hello;world");
- }),
- done
- );
- });
-
- it('should correctly extend template blocks with different sub-blocks', function(done) {
- qdone(
- testTpl('{% test4join separator=";" %}hello{% also %}the{% finally %}world{% endtest4join %}')
- .then(function(content) {
- assert.equal(content, "hello;the;world");
- }),
- done
- );
- });
- });
-});
diff --git a/test/plugins/blocks/index.js b/test/plugins/blocks/index.js
deleted file mode 100644
index 32f1910..0000000
--- a/test/plugins/blocks/index.js
+++ /dev/null
@@ -1,41 +0,0 @@
-var assert = require("assert");
-
-module.exports = {
- blocks: {
- "test": {
- shortcuts: {
- parsers: ["markdown"],
- start: "$$",
- end: "$$"
- },
- process: function(blk) {
- return "test"+blk.body+"test";
- }
- },
- "test2": {
- end: "endtest2end",
- process: function(blk) {
- return "test2"+blk.body+"test2";
- }
- },
- "test3join": {
- blocks: [
- "also"
- ],
- process: function(blk) {
- return [blk.body, blk.blocks[0].body].join(blk.kwargs.separator);
- }
- },
- "test4join": {
- blocks: [
- "also", "finally"
- ],
- process: function(blk) {
- assert(blk.blocks.length, 2);
- assert(blk.blocks[0].name, "also");
- assert(blk.blocks[1].name, "finally");
- return [blk.body, blk.blocks[0].body, blk.blocks[1].body].join(blk.kwargs.separator);
- }
- }
- }
-}; \ No newline at end of file
diff --git a/test/plugins/blocks/package.json b/test/plugins/blocks/package.json
deleted file mode 100644
index 7c41fd3..0000000
--- a/test/plugins/blocks/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "gitbook-plugin-blocks",
- "description": "Test blocks",
- "main": "index.js",
- "version": "0.0.1",
- "engines": {
- "gitbook": "*"
- }
-} \ No newline at end of file
diff --git a/test/plugins/empty/index.js b/test/plugins/empty/index.js
deleted file mode 100644
index a099545..0000000
--- a/test/plugins/empty/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = {}; \ No newline at end of file
diff --git a/test/plugins/empty/package.json b/test/plugins/empty/package.json
deleted file mode 100644
index 78c7e72..0000000
--- a/test/plugins/empty/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "gitbook-plugin-empty",
- "description": "Test empty plugin",
- "main": "index.js",
- "version": "0.0.1",
- "engines": {
- "gitbook": "*"
- }
-} \ No newline at end of file
diff --git a/test/plugins/filters/index.js b/test/plugins/filters/index.js
deleted file mode 100644
index 2cf53b1..0000000
--- a/test/plugins/filters/index.js
+++ /dev/null
@@ -1,10 +0,0 @@
-module.exports = {
- filters: {
- hello: function(text) {
- return "Hello "+text;
- },
- helloCtx: function(text) {
- return text+":"+this.book.root;
- }
- }
-}; \ No newline at end of file
diff --git a/test/plugins/filters/package.json b/test/plugins/filters/package.json
deleted file mode 100644
index f1d4e45..0000000
--- a/test/plugins/filters/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "gitbook-plugin-filters",
- "description": "Test filters",
- "main": "index.js",
- "version": "0.0.1",
- "engines": {
- "gitbook": "*"
- }
-} \ No newline at end of file
diff --git a/test/plugins/invalid/index.js b/test/plugins/invalid/index.js
deleted file mode 100644
index a099545..0000000
--- a/test/plugins/invalid/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = {}; \ No newline at end of file
diff --git a/test/plugins/invalid/package.json b/test/plugins/invalid/package.json
deleted file mode 100644
index da34090..0000000
--- a/test/plugins/invalid/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "gitbook-plugin-invalid",
- "description": "Test invalid plugin",
- "main": "index.js",
- "version": "0.0.1",
- "engines": {
- "gitbook": "<2.0.0"
- }
-} \ No newline at end of file
diff --git a/test/plugins/resources/index.js b/test/plugins/resources/index.js
deleted file mode 100644
index bafa54b..0000000
--- a/test/plugins/resources/index.js
+++ /dev/null
@@ -1,12 +0,0 @@
-module.exports = {
- website: {
- js: [
- "https://cdn.mathjax.org/mathjax/2.4-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
- ]
- },
- ebook: {
- css: [
- "test"
- ]
- }
-};
diff --git a/test/plugins/resources/package.json b/test/plugins/resources/package.json
deleted file mode 100644
index ab4320d..0000000
--- a/test/plugins/resources/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "gitbook-plugin-resources",
- "description": "Test resources plugin",
- "main": "index.js",
- "version": "0.0.1",
- "engines": {
- "gitbook": "*"
- }
-} \ No newline at end of file
diff --git a/test/templating.js b/test/templating.js
deleted file mode 100644
index 9165d7a..0000000
--- a/test/templating.js
+++ /dev/null
@@ -1,37 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-var fs = require("fs");
-
-var pkg = require("../package.json");
-
-describe('Templating', function () {
- before(function(done) {
- testGeneration(books[0], "website", function(output) {}, done);
- });
-
- var testTpl = function(str, args, options) {
- return books[0].template.renderString(str, args, options)
- .then(books[0].template.postProcess)
- };
-
- it('should correctly have access to generator', function(done) {
- qdone(
- testTpl('{{ gitbook.generator }}')
- .then(function(content) {
- assert.equal(content, "website");
- }),
- done
- );
- });
-
- it('should correctly have access to gitbook version', function(done) {
- qdone(
- testTpl('{{ gitbook.version }}')
- .then(function(content) {
- assert.equal(content, pkg.version.toString());
- }),
- done
- );
- });
-});
diff --git a/test/website.js b/test/website.js
deleted file mode 100644
index afbe7aa..0000000
--- a/test/website.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-
-var fs = require("fs");
-var fsUtil = require("../lib/utils/fs");
-
-
-describe('Website Generator', function () {
- it('should correctly generate a book to website', function(done) {
- testGeneration(books[1], "website", function(output) {
- assert(fs.existsSync(path.join(output, "index.html")));
- assert(fs.existsSync(path.join(output, "search_index.json")));
- }, done);
- });
-
- it('should correctly include styles in website', function(done) {
- testGeneration(books[0], "website", function(output) {
- assert(fs.existsSync(path.join(output, "styles/website.css")));
-
- var INDEX = fs.readFileSync(path.join(output, "index.html")).toString();
- assert(INDEX.indexOf("styles/website.css") > 0);
- }, done);
- });
-
- it('should correctly include glossary in website', function(done) {
- testGeneration(books[0], "website", function(output) {
- assert(fs.existsSync(path.join(output, "GLOSSARY.html")));
- }, done);
- });
-
- it('should correctly generate a multilingual book to website', function(done) {
- testGeneration(books[2], "website", function(output) {
- assert(fs.existsSync(path.join(output, "index.html")));
- assert(fs.existsSync(path.join(output, "gitbook")));
- assert(fs.existsSync(path.join(output, "fr/index.html")));
- assert(fs.existsSync(path.join(output, "en/index.html")));
- }, done);
- });
-});