summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-03-09 10:43:12 +0100
committerSamy Pessé <samypesse@gmail.com>2015-03-09 10:43:12 +0100
commit34fc2831e0cf0fed01c71cec28d93472d87f455b (patch)
treea803cc907c20491ba02863b5d3dd5aedf6bfed10 /test
parente1594cde2c32e4ff48f6c4eff3d3d461743d74e1 (diff)
parent1bf68a5aa0703b5a1815cfe4ebb731b5fb6ed9d2 (diff)
downloadgitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.zip
gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.gz
gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.bz2
Merge branch 'version/2.0'
Diffstat (limited to 'test')
-rwxr-xr-xtest/bin/lex.js16
-rwxr-xr-xtest/bin/summary.js16
-rw-r--r--test/configuration.js14
-rw-r--r--test/ebook.js36
-rw-r--r--test/fixtures/ALTERNATIVE_SUMMARY.md13
-rw-r--r--test/fixtures/FALSE_QUIZ.md120
-rw-r--r--test/fixtures/GITHUB_LINKS.md3
-rw-r--r--test/fixtures/GLOSSARY.md30
-rw-r--r--test/fixtures/HR_PAGE.md11
-rw-r--r--test/fixtures/IMAGES.md12
-rw-r--r--test/fixtures/INCLUDES.md29
-rw-r--r--test/fixtures/MARKDOWN_LINKS.md5
-rw-r--r--test/fixtures/PAGE.md68
-rw-r--r--test/fixtures/QUIZ_PAGE.md48
-rw-r--r--test/fixtures/README.md7
-rw-r--r--test/fixtures/SECTIONS.md68
-rw-r--r--test/fixtures/SUMMARY.md12
-rw-r--r--test/fixtures/SUMMARY_WHITESPACE.md15
-rw-r--r--test/fixtures/book1/README.md2
-rw-r--r--test/fixtures/book1/SUMMARY.md3
-rw-r--r--test/fixtures/book1/test.md1
-rw-r--r--test/fixtures/book2/README.md1
-rw-r--r--test/fixtures/included.c7
-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/en/SUMMARY.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/generate.js46
-rw-r--r--test/git.js32
-rw-r--r--test/glossary.js37
-rw-r--r--test/helper.js62
-rw-r--r--test/includes.js42
-rw-r--r--test/json.js59
-rw-r--r--test/links.js40
-rw-r--r--test/navigation.js101
-rw-r--r--test/page.js123
-rw-r--r--test/parsing.js82
-rw-r--r--test/plugin.js58
-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/readme.js28
-rw-r--r--test/sections.js22
-rw-r--r--test/summary.js71
-rw-r--r--test/templating.js37
-rw-r--r--test/website.js40
80 files changed, 851 insertions, 989 deletions
diff --git a/test/bin/lex.js b/test/bin/lex.js
deleted file mode 100755
index c35d399..0000000
--- a/test/bin/lex.js
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env node
-
-var fs = require('fs');
-
-var gitbook = require('../../');
-
-if(process.argv < 3) {
- console.error('Please specify a filename');
- process.exit(1);
-}
-
-var content = fs.readFileSync(process.argv[2], 'utf8');
-
-var lexed = gitbook.parse.lex(content);
-
-console.log(JSON.stringify(lexed, null, 2));
diff --git a/test/bin/summary.js b/test/bin/summary.js
deleted file mode 100755
index 78c20dc..0000000
--- a/test/bin/summary.js
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env node
-
-var fs = require('fs');
-
-var gitbook = require('../../');
-
-if(process.argv < 3) {
- console.error('Please specify a filename');
- process.exit(1);
-}
-
-var content = fs.readFileSync(process.argv[2], 'utf8');
-
-var lexed = gitbook.parse.summary(content);
-
-console.log(JSON.stringify(lexed, null, 2));
diff --git a/test/configuration.js b/test/configuration.js
new file mode 100644
index 0000000..e690f2c
--- /dev/null
+++ b/test/configuration.js
@@ -0,0 +1,14 @@
+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
new file mode 100644
index 0000000..d02e7cd
--- /dev/null
+++ b/test/ebook.js
@@ -0,0 +1,36 @@
+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/ALTERNATIVE_SUMMARY.md b/test/fixtures/ALTERNATIVE_SUMMARY.md
deleted file mode 100644
index e0d0114..0000000
--- a/test/fixtures/ALTERNATIVE_SUMMARY.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Summary
-
-* [Custom name for Introduction](README.md)
-* [Chapter 1](chapter-1/README.md)
- * [Article 1](chapter-1/ARTICLE1.md)
- * [Article 2](chapter-1/ARTICLE2.md)
- * [article 1.2.1](chapter-1/ARTICLE-1-2-1.md)
- * [article 1.2.2](chapter-1/ARTICLE-1-2-2.md)
-* [Chapter 2](chapter-2/README.md)
-* [Chapter 3](chapter-3/README.md)
-* [Chapter 4](chapter-4/README.md)
- * Unfinished article
-* Unfinished Chapter
diff --git a/test/fixtures/FALSE_QUIZ.md b/test/fixtures/FALSE_QUIZ.md
deleted file mode 100644
index 46f9a00..0000000
--- a/test/fixtures/FALSE_QUIZ.md
+++ /dev/null
@@ -1,120 +0,0 @@
-# Learn Node.js by Example
-
-
-## Requirements
-
-- [x] A computer with internet access
-- [ ] Time: 30h (e.g. 2 months 30 mins per day or **1 week intensive**)
-
-
-## What is Node.js ?
-
-Node.js lets you *easily* build networked software (websites, applications "apps",
-using JavaScript).
-
-Its not "*point-and-click*" like WordPress, SquareSpace or Salesforce;
-you will need to write some "code". But as I will demonstrate, that's
-a *lot* easier than it sounds and gives you more power/flexibility
-and puts you in full control.
-
-## Node.js is not "Version 1.0" yet can I used it in Production?
-
-Yes! Some of the biggest organisations/companies in the world
-are using Node.js in Production systems:
-
-[Alibaba](https://github.com/alibaba/node-hbase-client),
-[Ajax.org](Ajax.org),
-[Box.com](http://tech.blog.box.com/2014/06/node-js-high-availability-at-box/), British Sky Broadcasting (Sky/Now TV),
-CNN,
-[Cloudup](https://cloudup.com/),
-Conde Nast,
-[DirectTV](http://strongloop.com/strongblog/node-summit-media-companies-embrace-node-js-for-rapidly-developing-responsive-apps/),
-[Dow Jones](http://nodejs.org/industry),
-eBay,
-[FeedHenry](http://www.feedhenry.com/),
-[GitHub](https://twitter.com/github/status/16979699217465344),
-[Google](http://venturebeat.com/2012/01/24/node-at-google-mozilla-yahoo/),
-[Groupon](http://nodeup.com/fiftyeight),
-HBO,
-Help.com,
-[HP](https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node),
-iTV,
-[Joyent](https://www.joyent.com/) (duh!),
-[Klout](https://klout.com),
-LinkedIn,
-McDonalds,
-[Medium](https://medium.com/the-story),
-Mozilla,
-NetFlix,
-[OpenTable](http://hapijs.com/community),
-PayPal,
-Pearson,
-~~Q~~,
-[Revolt](http://revolt.tv/),
-[Square](https://modulus.io/companies-using-node),
-Tesco,
-ThomasCook,
-Trello,
-Uber,
-Voxer,
-Walmart,
-Wikimedia (in progress of moving to SOA with node!)
-Yahoo,
-Yammer,
-[Yandex](https://www.youtube.com/watch?v=zdCxgdH4wZo),
-[Zendesk](http://radar.zendesk.com/)
-
-Want more? See: http://nodejs.org/industry/ and <br />
-https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node
-
-
-# Try it!
-
-## Download & Install
-
-> http://nodejs.org/download/
-
-
-## Node.js (Core) API
-
-The node.js ("core") has many useful modules.
-
-Bookmark: [http://nodejs.org/api](http://nodejs.org/api/) (you will come back to it)
-
-
-
-## Stability (Can we use it?)
-
-> *Which node.js* ***core*** *package(s) can/should I use?*
-
-Every core module has a
-["***Stability Index***"](http://nodejs.org/api/documentation.html#documentation_stability_index)
-rating on the node.js API.
-
-**General rule**: If you are being *paid* to write code
-that runs in node.js, <br /> pick core modules/methods
-with stability **Stable**, **API Frozen** and **Locked**.
-
-![Node.js Stability Index](http://i.imgur.com/xIroFrS.png)
-
-
-### Examples
-
-- [**cluster**](http://nodejs.org/api/cluster.html) is ***Experimental*** - don't use
-- [**domain**](http://nodejs.org/api/domain.html) is ***Unstable*** - don't use
-- [**path**](http://nodejs.org/api/path.html) is ***Stable*** - use
-- [**events**](http://nodejs.org/api/events.html) is ***Frozen*** - use
-- [**assert**](http://nodejs.org/api/assert.html) is ***Locked*** - use
-
-Core Modules to Learn
-
-- path
-- os
-
-
-
-Community Modules to Learn:
-
-- [jscs](https://www.npmjs.org/package/jscs) - code style checker
-- [q](https://www.npmjs.org/package/q) - promises library
-- [nd](https://www.npmjs.org/package/nd) - view documentation for a module
diff --git a/test/fixtures/GITHUB_LINKS.md b/test/fixtures/GITHUB_LINKS.md
deleted file mode 100644
index f0039dd..0000000
--- a/test/fixtures/GITHUB_LINKS.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Nice course
-
-Check out this source file [in C++](../src/something.cpp)
diff --git a/test/fixtures/GLOSSARY.md b/test/fixtures/GLOSSARY.md
deleted file mode 100644
index 5969902..0000000
--- a/test/fixtures/GLOSSARY.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# Magic
-Sufficiently advanced technology, beyond the understanding of the observer producing a sense of wonder.
-
-Hello, I am random noise in the middle of this beautiful Glossary. (Really astonishing !)
-
-# PHP
-An atrocious language, invented for the sole purpose of inflicting pain and suffering amongst the proframming wizards of this world.
-
-# Clojure
-Lisp re-invented for hipsters.
-
-# Go
-Go Go Google [Wow](https://www.google.com)
-
-Fantastic, I love code too ! :
-
-```py
-
-def f(x):
- return x * 4
-
-# Wow this is some really awesome code
-# totally mind blowing
-# but we don't care, it shouldn't be in our glossary !
-print(f(9))
-```
-
-# Gitbook
-
-Awesome project. Really amazing, I'm really at a loss for words ...
diff --git a/test/fixtures/HR_PAGE.md b/test/fixtures/HR_PAGE.md
deleted file mode 100644
index 49115d0..0000000
--- a/test/fixtures/HR_PAGE.md
+++ /dev/null
@@ -1,11 +0,0 @@
-## Wow such book
-
-Some nice content here
-
----
-
-A beautiful separator, but non an exercise or a quiz !
-
----
-
-Some more beautiful text, because `this` book is awesome ...
diff --git a/test/fixtures/IMAGES.md b/test/fixtures/IMAGES.md
deleted file mode 100644
index 99ffa00..0000000
--- a/test/fixtures/IMAGES.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# Images Test
-
-This is a test for images path calculation. It supposed this fiel is in a syntax/ folder
-
-### #
-
-[![Screen](./preview.png)](./preview.png)
-
-### 2
-
-[![Screen](../preview2.png)](./preview2.png)
-
diff --git a/test/fixtures/INCLUDES.md b/test/fixtures/INCLUDES.md
deleted file mode 100644
index 22e3a61..0000000
--- a/test/fixtures/INCLUDES.md
+++ /dev/null
@@ -1,29 +0,0 @@
-# Beautiful chapter
-
-Here is a nice included snippet :
-
-```c
-{{ included.c }}
-```
-
-----
-
-An exercise using includes
-
-```c
-{{ included.c }}
-
-Remove this extra code at the end
-```
-
-```c
-{{ included.c }}
-```
-
-```c
-{{ included.c }}
-
-This validation code is wrong but who cares ?
-```
-
-----
diff --git a/test/fixtures/MARKDOWN_LINKS.md b/test/fixtures/MARKDOWN_LINKS.md
deleted file mode 100644
index e0d5820..0000000
--- a/test/fixtures/MARKDOWN_LINKS.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Nice course
-
-Check out this other chapter [Test](test.md)
-
-Check out this other chapter [Test](../before.md)
diff --git a/test/fixtures/PAGE.md b/test/fixtures/PAGE.md
deleted file mode 100644
index 77a6ce9..0000000
--- a/test/fixtures/PAGE.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# Python basics
-
-Python is a nice language, you can add stuff. Bla bla bla.
-
-Lets jump into an exercise :
-
----
-
-It's dead simple, `c` must be the sum of `a` and `b`
-
-```py
-a = 1
-b = 2
-```
-
-```py
-a = 1
-b = 2
-c = a + b
-```
-
-```py
-assert(c, 3)
-```
-
----
-
-Some more nice content ....
-
-[Cool stuff](http://gitbook.com)
-
-[Link to another Markdown file](./xyz/file.md)
-
-And look at this pretty picture:
-![Pretty](../assets/my-pretty-picture.png "Pretty")
-
-Lets go for another exercise but this time with some context :
-
----
-
-Exercise with some context code :
-
-Using the `double` function provided, build a `quadruple` function
-
-```py
-
-```
-
-```py
-
-def quadruple(x):
- return double(double(x))
-
-```
-
-```py
-assert(quadruple(8), 32)
-```
-
-```py
-
-def double(x):
- return x * 2
-
-```
-
----
-
diff --git a/test/fixtures/QUIZ_PAGE.md b/test/fixtures/QUIZ_PAGE.md
deleted file mode 100644
index 21b2a9d..0000000
--- a/test/fixtures/QUIZ_PAGE.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# Gitbook quiz
-
-Gitbook lets you write a quiz using GFM tables:
-
----
-
-Here's a quiz about Gitbook
-
-| | Good | Bad |
-| ---------------- | ---- | --- |
-| What is Gitbook? | (x) | ( ) |
-
-> Gitbook is good
-
-What does Gitbook support?
-- [x] Table-based questions with radio buttons
-- [x] Table-based questions with checkboxes
-- [ ] Telepathy
-- [x] List-based questions with checkboxes
-- [x] List-based questions with radio buttons
-- [ ] Moon-on-a-stick
-
-> Gitbook supports table and list based quiz questions using either radio buttons or checkboxes.
->
-> Gitbook is not telepathic and does not give you the moon on a stick.
-
----
-
-Some more nice content ....
-
-[Cool stuff](http://gitbook.com)
-
-[Link to another Markdown file](./xyz/file.md)
-
----
-
-Quiz test 2: What does Gitbook support?
-- [x] Table-based questions with radio buttons
-- [x] Table-based questions with checkboxes
-- [ ] Telepathy
-- [x] List-based questions with checkboxes
-- [x] List-based questions with radio buttons
-- [ ] Moon-on-a-stick
-
-> Gitbook supports table and list based quiz questions using either radio buttons or checkboxes.
-
----
-
diff --git a/test/fixtures/README.md b/test/fixtures/README.md
deleted file mode 100644
index 7e20198..0000000
--- a/test/fixtures/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# This is the title
-
-This is the book description.
-
-other content
-...
-
diff --git a/test/fixtures/SECTIONS.md b/test/fixtures/SECTIONS.md
deleted file mode 100644
index 3405605..0000000
--- a/test/fixtures/SECTIONS.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# Title
-
-Some text
-
----
-
-## NOT Exercise
-
-Simple subsection NOT exercise
-
-```
-x = 1
-```
-
-What is this
-
-```
-y = [1, 2, 3]
-```
-
-```
-z = {a: 1, b: 2}
-```
-
----
-
-## Exercise
-
-Define a variable `x` equal to 10.
-
-```js
-var x =
-```
-
-```js
-var x = 10;
-```
-
-```js
-assert(x == 10);
-```
-
-```js
-// This is context code available everywhere
-// The user will be able to call magicFunc in his code
-function magicFunc() {
- return 3;
-}
-```
-
----
-
-## Another exercise
-
-Bla bla bla ... This time with no `context` code.
-
-
-```js
-var x =
-```
-
-```js
-var x = 10;
-```
-
-```js
-assert(x == 10);
-```
diff --git a/test/fixtures/SUMMARY.md b/test/fixtures/SUMMARY.md
deleted file mode 100644
index 3bf4a88..0000000
--- a/test/fixtures/SUMMARY.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# Summary
-
-* [Chapter 1](chapter-1/README.md)
- * [Article 1](chapter-1/ARTICLE1.md)
- * [Article 2](chapter-1/ARTICLE2.md)
- * [article 1.2.1](\chapter-1\ARTICLE-1-2-1.md)
- * [article 1.2.2](/chapter-1/ARTICLE-1-2-2.md)
-* [Chapter 2](chapter-2/README.md)
-* [Chapter 3](chapter-3/README.md)
-* [Chapter 4](chapter-4/README.md)
- * Unfinished article
-* Unfinished Chapter
diff --git a/test/fixtures/SUMMARY_WHITESPACE.md b/test/fixtures/SUMMARY_WHITESPACE.md
deleted file mode 100644
index 10a7100..0000000
--- a/test/fixtures/SUMMARY_WHITESPACE.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# Summary
-
-* [Chapter 1](chapter-1/README.md)
- * [Article 1](chapter-1/ARTICLE1.md)
- * [Article 2](chapter-1/ARTICLE2.md)
- * [article 1.2.1](\chapter-1\ARTICLE-1-2-1.md)
- * [article 1.2.2](/chapter-1/ARTICLE-1-2-2.md)
-
-* [Chapter 2](chapter-2/README.md)
-* [Chapter 3](chapter-3/README.md)
-* [Chapter 4](chapter-4/README.md)
-
- * Unfinished article
-
-* Unfinished Chapter
diff --git a/test/fixtures/book1/README.md b/test/fixtures/book1/README.md
deleted file mode 100644
index c01d3fb..0000000
--- a/test/fixtures/book1/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# This is a test
-
diff --git a/test/fixtures/book1/SUMMARY.md b/test/fixtures/book1/SUMMARY.md
deleted file mode 100644
index 20ec7b8..0000000
--- a/test/fixtures/book1/SUMMARY.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Summary
-
-* [test](test.md) \ No newline at end of file
diff --git a/test/fixtures/book1/test.md b/test/fixtures/book1/test.md
deleted file mode 100644
index 8ae0569..0000000
--- a/test/fixtures/book1/test.md
+++ /dev/null
@@ -1 +0,0 @@
-# Test
diff --git a/test/fixtures/book2/README.md b/test/fixtures/book2/README.md
deleted file mode 100644
index 13c54db..0000000
--- a/test/fixtures/book2/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# This should fail
diff --git a/test/fixtures/included.c b/test/fixtures/included.c
deleted file mode 100644
index d9323e3..0000000
--- a/test/fixtures/included.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <stdio.h>
-
-int main(int argc, char *argv[]) {
- printf("All is well\n");
-
- return 0;
-}
diff --git a/test/fixtures/test0/GLOSSARY.md b/test/fixtures/test0/GLOSSARY.md
new file mode 100644
index 0000000..ad07f86
--- /dev/null
+++ b/test/fixtures/test0/GLOSSARY.md
@@ -0,0 +1,6 @@
+# Glossary
+
+## Description
+
+This is the dexcription of a description.
+
diff --git a/test/fixtures/test0/README.md b/test/fixtures/test0/README.md
new file mode 100644
index 0000000..a2fdfea
--- /dev/null
+++ b/test/fixtures/test0/README.md
@@ -0,0 +1,3 @@
+# Other Title
+
+This is a description, it's simple, no ?
diff --git a/test/fixtures/test0/SUMMARY.md b/test/fixtures/test0/SUMMARY.md
new file mode 100644
index 0000000..27870e5
--- /dev/null
+++ b/test/fixtures/test0/SUMMARY.md
@@ -0,0 +1 @@
+# Summary \ No newline at end of file
diff --git a/test/fixtures/test0/book.json b/test/fixtures/test0/book.json
new file mode 100644
index 0000000..a2191b8
--- /dev/null
+++ b/test/fixtures/test0/book.json
@@ -0,0 +1,3 @@
+{
+ "title": "Test"
+} \ No newline at end of file
diff --git a/test/fixtures/test0/styles/website.css b/test/fixtures/test0/styles/website.css
new file mode 100644
index 0000000..f0d5b13
--- /dev/null
+++ b/test/fixtures/test0/styles/website.css
@@ -0,0 +1,3 @@
+body {
+ background: red;
+}
diff --git a/test/fixtures/test1/GLOSSARY.md b/test/fixtures/test1/GLOSSARY.md
new file mode 100644
index 0000000..dc14550
--- /dev/null
+++ b/test/fixtures/test1/GLOSSARY.md
@@ -0,0 +1,9 @@
+
+# Test
+
+a test text
+
+# Test 2
+
+a second test
+
diff --git a/test/fixtures/test1/README.md b/test/fixtures/test1/README.md
new file mode 100644
index 0000000..2f7a8d4
--- /dev/null
+++ b/test/fixtures/test1/README.md
@@ -0,0 +1,4 @@
+# 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
new file mode 100644
index 0000000..d05fc4a
--- /dev/null
+++ b/test/fixtures/test1/SUMMARY.md
@@ -0,0 +1,6 @@
+# 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
new file mode 100644
index 0000000..82c15c3
--- /dev/null
+++ b/test/fixtures/test1/book.json
@@ -0,0 +1,5 @@
+{
+ "structure": {
+ "readme": "intro.md"
+ }
+} \ No newline at end of file
diff --git a/test/fixtures/test1/intro.md b/test/fixtures/test1/intro.md
new file mode 100644
index 0000000..bf9a1cf
--- /dev/null
+++ b/test/fixtures/test1/intro.md
@@ -0,0 +1,4 @@
+# My Book
+
+Test description
+
diff --git a/test/fixtures/test1/sub/test1.md b/test/fixtures/test1/sub/test1.md
new file mode 100644
index 0000000..d45a4dd
--- /dev/null
+++ b/test/fixtures/test1/sub/test1.md
@@ -0,0 +1,8 @@
+# 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
new file mode 100644
index 0000000..a501d22
--- /dev/null
+++ b/test/fixtures/test2/LANGS.md
@@ -0,0 +1,4 @@
+# Languages
+
+* [English](en/)
+* [French](fr/)
diff --git a/test/fixtures/test2/README.md b/test/fixtures/test2/README.md
new file mode 100644
index 0000000..c6186ac
--- /dev/null
+++ b/test/fixtures/test2/README.md
@@ -0,0 +1,2 @@
+# Multi-Languages test
+
diff --git a/test/fixtures/test2/en/README.md b/test/fixtures/test2/en/README.md
new file mode 100644
index 0000000..95bc71c
--- /dev/null
+++ b/test/fixtures/test2/en/README.md
@@ -0,0 +1 @@
+# English Book
diff --git a/test/fixtures/test2/en/SUMMARY.md b/test/fixtures/test2/en/SUMMARY.md
new file mode 100644
index 0000000..ac9323c
--- /dev/null
+++ b/test/fixtures/test2/en/SUMMARY.md
@@ -0,0 +1 @@
+# Summary
diff --git a/test/fixtures/test2/fr/README.md b/test/fixtures/test2/fr/README.md
new file mode 100644
index 0000000..c7a4103
--- /dev/null
+++ b/test/fixtures/test2/fr/README.md
@@ -0,0 +1 @@
+# French Book
diff --git a/test/fixtures/test2/fr/SUMMARY.md b/test/fixtures/test2/fr/SUMMARY.md
new file mode 100644
index 0000000..ac9323c
--- /dev/null
+++ b/test/fixtures/test2/fr/SUMMARY.md
@@ -0,0 +1 @@
+# Summary
diff --git a/test/fixtures/test3/README.adoc b/test/fixtures/test3/README.adoc
new file mode 100644
index 0000000..ea295ee
--- /dev/null
+++ b/test/fixtures/test3/README.adoc
@@ -0,0 +1,4 @@
+= My Book
+
+Test description
+
diff --git a/test/fixtures/test3/SUMMARY.adoc b/test/fixtures/test3/SUMMARY.adoc
new file mode 100644
index 0000000..29fcb65
--- /dev/null
+++ b/test/fixtures/test3/SUMMARY.adoc
@@ -0,0 +1,5 @@
+= 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
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/fixtures/test3/test.adoc
diff --git a/test/fixtures/test3/test1.adoc b/test/fixtures/test3/test1.adoc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/fixtures/test3/test1.adoc
diff --git a/test/fixtures/test3/test2.adoc b/test/fixtures/test3/test2.adoc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/fixtures/test3/test2.adoc
diff --git a/test/fixtures/test4/README.md b/test/fixtures/test4/README.md
new file mode 100644
index 0000000..d73be69
--- /dev/null
+++ b/test/fixtures/test4/README.md
@@ -0,0 +1,11 @@
+# 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
new file mode 100644
index 0000000..3cda114
--- /dev/null
+++ b/test/fixtures/test4/SUMMARY.md
@@ -0,0 +1,3 @@
+# Summary
+
+* [Page](sub/PAGE.md)
diff --git a/test/fixtures/test4/book.js b/test/fixtures/test4/book.js
new file mode 100644
index 0000000..bf617cd
--- /dev/null
+++ b/test/fixtures/test4/book.js
@@ -0,0 +1,3 @@
+module.exports = {
+ title: "Test 2"
+};
diff --git a/test/fixtures/test4/sub/PAGE.md b/test/fixtures/test4/sub/PAGE.md
new file mode 100644
index 0000000..a98a942
--- /dev/null
+++ b/test/fixtures/test4/sub/PAGE.md
@@ -0,0 +1,18 @@
+##
+
+## 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
new file mode 100644
index 0000000..417f2c1
--- /dev/null
+++ b/test/fixtures/test4/test.svg
@@ -0,0 +1,11 @@
+<?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
new file mode 100644
index 0000000..3db21b2
--- /dev/null
+++ b/test/fixtures/test5/README.md
@@ -0,0 +1,5 @@
+# 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
new file mode 100644
index 0000000..ac9323c
--- /dev/null
+++ b/test/fixtures/test5/SUMMARY.md
@@ -0,0 +1 @@
+# Summary
diff --git a/test/fixtures/test5/test.md b/test/fixtures/test5/test.md
new file mode 100644
index 0000000..5e1c309
--- /dev/null
+++ b/test/fixtures/test5/test.md
@@ -0,0 +1 @@
+Hello World \ No newline at end of file
diff --git a/test/generate.js b/test/generate.js
deleted file mode 100644
index c38566a..0000000
--- a/test/generate.js
+++ /dev/null
@@ -1,46 +0,0 @@
-var _ = require('lodash');
-var Q = require('q');
-var path = require('path');
-var tmp = require('tmp');
-var assert = require('assert');
-
-var generate = require("../lib/generate");
-
-var generateTmpBook = function(path) {
- return ;
-};
-
-
-var BOOKS = {
- "book1": true,
- "book2": false
-};
-
-describe('Site Generation', function () {
- var ret = {};
-
- beforeEach(function(done){
- Q.all(_.map(BOOKS, function(state, bookName) {
- return Q.nfcall(tmp.dir)
- .then(function(_dir) {
- return generate.folder({
- input: path.join(__dirname, "fixtures", bookName),
- output: _dir
- });
- })
- .then(function(_book) {
- ret[bookName] = _book;
- }, function(err) {
- // ignore errors here
- });
- }))
- .fin(done);
- });
-
-
- it('should generate the valid sites', function() {
- _.each(BOOKS, function(state, bookName) {
- assert((ret[bookName] != null) == state);
- });
- });
-});
diff --git a/test/git.js b/test/git.js
new file mode 100644
index 0000000..9d48606
--- /dev/null
+++ b/test/git.js
@@ -0,0 +1,32 @@
+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
index bf40e16..5deb04c 100644
--- a/test/glossary.js
+++ b/test/glossary.js
@@ -1,20 +1,35 @@
-var fs = require('fs');
var path = require('path');
+var _ = require('lodash');
var assert = require('assert');
+var cheerio = require('cheerio');
-var glossary = require('../').parse.glossary;
+var fs = require("fs");
+var fsUtil = require("../lib/utils/fs");
-var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GLOSSARY.md'), 'utf8');
-var LEXED = glossary(CONTENT);
-describe('Glossary parsing', function () {
- it('should only get heading + paragraph pairs', function() {
- assert.equal(LEXED.length, 5);
+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 output simple name/description objects', function() {
- assert.equal(true, !(LEXED.some(function(e) {
- return !Boolean(e.name && e.description);
- })));
+ 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
new file mode 100644
index 0000000..5e16bc0
--- /dev/null
+++ b/test/helper.js
@@ -0,0 +1,62 @@
+var path = require('path');
+var Q = require('q');
+var fs = require('fs');
+var _ = require('lodash');
+
+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();
+};
+
+// 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);
+};
+
+// Books for testings
+var books = fs.readdirSync(path.join(__dirname, './fixtures/'));
+
+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
+ });
+ })
+ .compact()
+ .value();
+
+// Init before doing tests
+before(function(done) {
+
+ qdone(
+ _.reduce(global.books, function(prev, book) {
+ return prev.then(function() {
+ return fsUtil.remove(path.join(book.root, "_book"));
+ })
+ .then(function() {
+ return book.parse();
+ });
+ }, Q()),
+ done
+ );
+});
diff --git a/test/includes.js b/test/includes.js
deleted file mode 100644
index 6954d3f..0000000
--- a/test/includes.js
+++ /dev/null
@@ -1,42 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var page = require('../').parse.page;
-var includer = require('../').parse.includer;
-
-var FIXTURES_DIR = path.join(__dirname, './fixtures/');
-
-function loadPage (name, options) {
- var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
- return page(CONTENT, options).sections;
-}
-
-
-describe('Code includes', function() {
-
- var LEXED = loadPage('INCLUDES', {
- 'dir': FIXTURES_DIR,
- 'includer': includer({}, [
- FIXTURES_DIR
- ], path.join, fs.readFileSync)
- });
-
- var INCLUDED_C = fs.readFileSync(path.join(FIXTURES_DIR, 'included.c'), 'utf8');
-
- it('should work for snippets', function() {
- assert.equal(LEXED[0].type, 'normal');
- // Has replaced include
- assert.equal(
- LEXED[0].content.indexOf('{{ included.c }}'),
- -1
- );
- });
-
- it('should work for exercises', function() {
- assert.equal(LEXED[1].type, 'exercise');
-
- // Solution is trimmed version of source
- assert.equal(LEXED[1].code.solution, INCLUDED_C.trim());
- });
-});
diff --git a/test/json.js b/test/json.js
new file mode 100644
index 0000000..e0ad14f
--- /dev/null
+++ b/test/json.js
@@ -0,0 +1,59 @@
+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("intro.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);
+ });
+});
diff --git a/test/links.js b/test/links.js
new file mode 100644
index 0000000..2c68a23
--- /dev/null
+++ b/test/links.js
@@ -0,0 +1,40 @@
+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/navigation.js b/test/navigation.js
deleted file mode 100644
index df29509..0000000
--- a/test/navigation.js
+++ /dev/null
@@ -1,101 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var summary = require('../').parse.summary;
-var navigation = require('../').parse.navigation;
-
-
-var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8');
-var ALT_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/ALTERNATIVE_SUMMARY.md'), 'utf8');
-var LEXED = summary(CONTENT);
-var ALT_LEXED = summary(ALT_CONTENT);
-
-
-describe('Summary navigation', function() {
- it('should provide next & prev entries for a file', function() {
- var nav = navigation(LEXED, [
- 'README.md',
- 'chapter-1/README.md',
- 'chapter-1/ARTICLE1.md',
- 'chapter-1/ARTICLE2.md',
- 'chapter-2/README.md',
- 'chapter-1/ARTICLE-1-2-1.md',
- 'chapter-1/ARTICLE-1-2-2.md'
- ]);
-
- // Make sure it found the files we gave it
- assert(nav['README.md']);
- assert(nav['chapter-1/README.md']);
- assert(nav['chapter-1/ARTICLE1.md']);
- assert(nav['chapter-1/ARTICLE2.md']);
- assert(nav['chapter-2/README.md']);
- assert(nav['chapter-1/ARTICLE-1-2-1.md']);
- assert(nav['chapter-1/ARTICLE-1-2-2.md']);
-
-
- assert.equal(nav['README.md'].prev, null);
- assert.equal(nav['README.md'].next.path, 'chapter-1/README.md');
-
- assert.equal(nav['chapter-1/README.md'].prev.path, 'README.md');
- assert.equal(nav['chapter-1/README.md'].next.path, 'chapter-1/ARTICLE1.md');
-
- assert.equal(nav['chapter-1/ARTICLE1.md'].prev.path, 'chapter-1/README.md');
- assert.equal(nav['chapter-1/ARTICLE1.md'].next.path, 'chapter-1/ARTICLE2.md');
-
- assert.equal(nav['chapter-1/ARTICLE2.md'].prev.path, 'chapter-1/ARTICLE1.md');
- assert.equal(nav['chapter-1/ARTICLE2.md'].next.path, 'chapter-1/ARTICLE-1-2-1.md');
-
- assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].prev.path, 'chapter-1/ARTICLE2.md');
- assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].next.path, 'chapter-1/ARTICLE-1-2-2.md');
-
- assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].prev.path, 'chapter-1/ARTICLE-1-2-1.md');
- assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].next.path, 'chapter-2/README.md');
-
- assert.equal(nav['chapter-2/README.md'].prev.path, 'chapter-1/ARTICLE-1-2-2.md');
- assert.equal(nav['chapter-2/README.md'].next.path, 'chapter-3/README.md');
- });
-
- it('should give full tree, when not limited', function() {
- var nav = navigation(LEXED);
-
- assert(nav['README.md']);
- assert(nav['chapter-1/README.md']);
- assert(nav['chapter-1/ARTICLE1.md']);
- assert(nav['chapter-1/ARTICLE2.md']);
- assert(nav['chapter-2/README.md']);
- assert(nav['chapter-3/README.md']);
- });
-
- it('should detect levels correctly', function() {
- var nav = navigation(LEXED);
-
- assert.equal(nav['README.md'].level, '0');
- assert.equal(nav['chapter-1/README.md'].level, '1');
- assert.equal(nav['chapter-1/ARTICLE1.md'].level, '1.1');
- assert.equal(nav['chapter-1/ARTICLE2.md'].level, '1.2');
- assert.equal(nav['chapter-2/README.md'].level, '2');
- assert.equal(nav['chapter-3/README.md'].level, '3');
- });
-
- it('should have a default README node', function() {
- var nav = navigation(LEXED);
-
- assert.equal(nav['README.md'].level, '0');
- assert.equal(nav['README.md'].title, 'Introduction');
- });
-
- it('Should allow README node to be customized', function() {
- var nav = navigation(ALT_LEXED);
-
- assert(nav['README.md']);
- assert.equal(nav['README.md'].level, '0');
- assert.notEqual(nav['README.md'].title, 'Introduction');
- });
-
- it('should not accept null paths', function() {
- var nav = navigation(LEXED);
-
- assert(!nav[null]);
- });
-});
diff --git a/test/page.js b/test/page.js
deleted file mode 100644
index c883367..0000000
--- a/test/page.js
+++ /dev/null
@@ -1,123 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var page = require('../').parse.page;
-
-function loadPage (name, options) {
- var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8');
- return page(CONTENT, options).sections;
-}
-
-var LEXED = loadPage('PAGE', {
- dir: 'course',
- outdir: '_book'
-});
-var QUIZ_LEXED = loadPage('QUIZ_PAGE');
-var HR_LEXED = loadPage('HR_PAGE');
-
-describe('Page parsing', function() {
- it('should detect sections', function() {
- assert.equal(LEXED.length, 4);
- });
-
- it('should detect section types', function() {
- assert.equal(LEXED[0].type, 'normal');
- assert.equal(LEXED[1].type, 'exercise');
- assert.equal(LEXED[2].type, 'normal');
- assert.equal(QUIZ_LEXED[0].type, 'normal');
- assert.equal(QUIZ_LEXED[1].type, 'quiz');
- assert.equal(QUIZ_LEXED[2].type, 'normal');
- assert.equal(QUIZ_LEXED[3].type, 'quiz');
- });
-
- it('should gen content for normal sections', function() {
- assert(LEXED[0].content);
- assert(LEXED[2].content);
- });
-
- it('should gen code and content for exercise sections', function() {
- assert(LEXED[1].content);
- assert(LEXED[1].code);
- assert(LEXED[1].code.base);
- assert(LEXED[1].code.solution);
- assert(LEXED[1].code.validation);
- assert(LEXED[1].code.context === null);
-
- assert(LEXED[3].content);
- assert(LEXED[3].code);
- assert(LEXED[3].code.base);
- assert(LEXED[3].code.solution);
- assert(LEXED[3].code.validation);
- assert(LEXED[3].code.context);
- });
-
- it('should merge sections correctly', function() {
- // One big section
- assert.equal(HR_LEXED.length, 1);
-
- // HRs inserted correctly
- assert.equal(HR_LEXED[0].content.match(/<hr>/g).length, 2);
- });
-
- it('should detect an exercise\'s language', function() {
- assert.equal(LEXED[1].lang, 'python');
- });
-
- it('should render a quiz', function() {
- assert(QUIZ_LEXED[1].content);
- assert(QUIZ_LEXED[1].quiz);
- assert(QUIZ_LEXED[1].quiz[0].base);
- assert(QUIZ_LEXED[1].quiz[0].solution);
- assert(QUIZ_LEXED[1].quiz[0].feedback);
- assert(QUIZ_LEXED[1].quiz[1].base);
- assert(QUIZ_LEXED[1].quiz[1].solution);
- assert(QUIZ_LEXED[1].quiz[1].feedback);
- });
-});
-
-
-describe('Relative links', function() {
- it('should replace link to .md by link to .html', function() {
- var LEXED = loadPage('MARKDOWN_LINKS', {
- // Imaginary folder of markdown file
- dir: 'course',
- outdir: 'course'
- });
-
- assert(LEXED[0].content.indexOf('test.html') !== -1);
- assert(LEXED[0].content.indexOf('../before.html') !== -1);
- });
-});
-
-describe('Relative images', function() {
- it('should keep image relative with considering output directory in site format', function() {
- var LEXED = loadPage('IMAGES', {
- // Imaginary folder of markdown file
- dir: 'syntax',
- outdir: 'syntax'
- });
-
- assert(LEXED[0].content.indexOf('"preview.png"') !== -1);
- assert(LEXED[0].content.indexOf('"../preview2.png"') !== -1);
- });
-
- it('should keep image relative with considering output directory in page format', function() {
- var LEXED = loadPage('IMAGES', {
- // Imaginary folder of markdown file
- dir: 'syntax',
- outdir: './'
- });
-
- assert(LEXED[0].content.indexOf('"syntax/preview.png"') !== -1);
- assert(LEXED[0].content.indexOf('"preview2.png"') !== -1);
- });
-});
-
-describe('Section parsing', function() {
- it('should not have false positive quiz parsing', function() {
- var LEXED = loadPage('FALSE_QUIZ');
-
- assert.equal(LEXED[0].type, 'normal');
- });
-});
diff --git a/test/parsing.js b/test/parsing.js
new file mode 100644
index 0000000..fcda739
--- /dev/null
+++ b/test/parsing.js
@@ -0,0 +1,82 @@
+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, "Introduction");
+ 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, "Introduction");
+ assert.equal(NAVIGATION["sub/test1.md"].next, null);
+ });
+});
diff --git a/test/plugin.js b/test/plugin.js
deleted file mode 100644
index fcde67c..0000000
--- a/test/plugin.js
+++ /dev/null
@@ -1,58 +0,0 @@
-var _ = require('lodash');
-var path = require('path');
-var assert = require('assert');
-
-var Plugin = require('../').generate.Plugin;
-
-describe('Plugin validation', function () {
- var plugin = new Plugin("plugin", __dirname);
-
- it('should be valid', function() {
- assert(plugin.isValid());
- });
-});
-
-describe('Plugins list', function () {
- var firstDefault = _.first(Plugin.defaults);
-
- it('should convert string to array', function() {
- var _name = "test";
- assert(_.contains(Plugin.normalizeNames(_name), _name));
- });
-
- it('should contains default plugins', function() {
- assert(_.contains(Plugin.normalizeNames([]), firstDefault));
- });
-
- it('should remove name starting with -', function() {
- assert(!_.contains(Plugin.normalizeNames(["-"+firstDefault]), firstDefault));
- });
-
- it('should accept version', function() {
- var _name = "test@0.3.0,exercises@1.2.0,test2";
- var plugins = Plugin.normalizeList(_name);
-
- assert(_.find(plugins, {'name': "test"}).version = "0.3.0");
- assert(_.find(plugins, {'name': "exercises"}).version = "1.2.0");
- assert(!_.find(plugins, {'name': "test2"}).version);
- });
-});
-
-describe('Plugin defaults loading', function () {
- var ret = true;
-
- beforeEach(function(done){
- Plugin.fromList(Plugin.defaults, __dirname)
- .then(function(_r) {
- ret = _r;
- }, function(err) {
- ret = null;
- })
- .fin(done);
- });
-
-
- it('should load defaults addons', function() {
- assert(ret != null);
- });
-});
diff --git a/test/plugins.js b/test/plugins.js
new file mode 100644
index 0000000..c7d1f90
--- /dev/null
+++ b/test/plugins.js
@@ -0,0 +1,189 @@
+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
new file mode 100644
index 0000000..0a02ff7
--- /dev/null
+++ b/test/plugins/blocks/index.js
@@ -0,0 +1,41 @@
+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
new file mode 100644
index 0000000..7c41fd3
--- /dev/null
+++ b/test/plugins/blocks/package.json
@@ -0,0 +1,9 @@
+{
+ "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
new file mode 100644
index 0000000..a099545
--- /dev/null
+++ b/test/plugins/empty/index.js
@@ -0,0 +1 @@
+module.exports = {}; \ No newline at end of file
diff --git a/test/plugins/empty/package.json b/test/plugins/empty/package.json
new file mode 100644
index 0000000..78c7e72
--- /dev/null
+++ b/test/plugins/empty/package.json
@@ -0,0 +1,9 @@
+{
+ "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
new file mode 100644
index 0000000..0e2f1a2
--- /dev/null
+++ b/test/plugins/filters/index.js
@@ -0,0 +1,10 @@
+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
new file mode 100644
index 0000000..f1d4e45
--- /dev/null
+++ b/test/plugins/filters/package.json
@@ -0,0 +1,9 @@
+{
+ "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
new file mode 100644
index 0000000..a099545
--- /dev/null
+++ b/test/plugins/invalid/index.js
@@ -0,0 +1 @@
+module.exports = {}; \ No newline at end of file
diff --git a/test/plugins/invalid/package.json b/test/plugins/invalid/package.json
new file mode 100644
index 0000000..da34090
--- /dev/null
+++ b/test/plugins/invalid/package.json
@@ -0,0 +1,9 @@
+{
+ "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
new file mode 100644
index 0000000..d98d6f0
--- /dev/null
+++ b/test/plugins/resources/index.js
@@ -0,0 +1,12 @@
+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
new file mode 100644
index 0000000..ab4320d
--- /dev/null
+++ b/test/plugins/resources/package.json
@@ -0,0 +1,9 @@
+{
+ "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/readme.js b/test/readme.js
deleted file mode 100644
index 811591c..0000000
--- a/test/readme.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var readme = require('../').parse.readme;
-
-
-var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.md'), 'utf8');
-var LEXED = readme(CONTENT);
-
-describe('Readme parsing', function () {
-
- it('should contain a title', function() {
- assert(LEXED.title);
- });
-
- it('should contain a description', function() {
- assert(LEXED.description);
- });
-
- it('should extract the right title', function() {
- assert.equal(LEXED.title, "This is the title");
- });
-
- it('should extract the right description', function() {
- assert.equal(LEXED.description, "This is the book description.");
- });
-});
diff --git a/test/sections.js b/test/sections.js
deleted file mode 100644
index ef4abf9..0000000
--- a/test/sections.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var lex = require('../').parse.lex;
-
-
-var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SECTIONS.md'), 'utf8');
-var LEXED = lex(CONTENT);
-
-
-describe('Section parsing', function() {
- it('should correctly split sections', function() {
- assert.equal(LEXED.length, 3);
- });
-
- it('should robustly detect exercises', function() {
- assert.equal(LEXED[0].type, 'normal');
- assert.equal(LEXED[1].type, 'exercise');
- assert.equal(LEXED[2].type, 'exercise');
- });
-});
diff --git a/test/summary.js b/test/summary.js
deleted file mode 100644
index 616b983..0000000
--- a/test/summary.js
+++ /dev/null
@@ -1,71 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var assert = require('assert');
-
-var summary = require('../').parse.summary;
-
-function lex(fixtureFile) {
- return summary(
- fs.readFileSync(
- path.join(__dirname, 'fixtures', fixtureFile),
- 'utf8'
- )
- );
-}
-
-var LEXED = lex('SUMMARY.md');
-
-describe('Summary parsing', function () {
-
- it('should detect chapters', function() {
- assert.equal(LEXED.chapters.length, 6);
- });
-
- it('should support articles', function() {
- assert.equal(LEXED.chapters[1].articles.length, 2);
- assert.equal(LEXED.chapters[2].articles.length, 0);
- assert.equal(LEXED.chapters[3].articles.length, 0);
- });
-
- it('should detect paths and titles', function() {
- assert(LEXED.chapters[0].path);
- assert(LEXED.chapters[1].path);
- assert(LEXED.chapters[2].path);
- assert(LEXED.chapters[3].path);
- assert(LEXED.chapters[4].path);
- assert.equal(LEXED.chapters[5].path, null);
-
- assert(LEXED.chapters[0].title);
- assert(LEXED.chapters[1].title);
- assert(LEXED.chapters[2].title);
- assert(LEXED.chapters[3].title);
- assert(LEXED.chapters[4].title);
- assert(LEXED.chapters[5].title);
- });
-
- it('should normalize paths from .md to .html', function() {
- assert.equal(LEXED.chapters[0].path,'README.md');
- assert.equal(LEXED.chapters[1].path,'chapter-1/README.md');
- assert.equal(LEXED.chapters[2].path,'chapter-2/README.md');
- assert.equal(LEXED.chapters[3].path,'chapter-3/README.md');
- });
-
- it('should detect levels correctly', function() {
- var c = LEXED.chapters;
-
- assert.equal(c[0].level, '0');
- assert.equal(c[1].level, '1');
- assert.equal(c[2].level, '2');
- assert.equal(c[3].level, '3');
-
- assert.equal(c[1].articles[0].level, '1.1');
- assert.equal(c[1].articles[1].level, '1.2');
- assert.equal(c[1].articles[1].articles[0].level, '1.2.1');
- });
-
- it('should allow lists separated by whitespace', function() {
- var l = lex('SUMMARY_WHITESPACE.md');
-
- assert.equal(l.chapters.length, 6);
- });
-});
diff --git a/test/templating.js b/test/templating.js
new file mode 100644
index 0000000..9165d7a
--- /dev/null
+++ b/test/templating.js
@@ -0,0 +1,37 @@
+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
new file mode 100644
index 0000000..afbe7aa
--- /dev/null
+++ b/test/website.js
@@ -0,0 +1,40 @@
+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);
+ });
+});