summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-19 15:26:31 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-19 15:26:31 +0100
commit793600ab2fe3923062b06dd25e59655805882409 (patch)
treec385fbadece8b41b69dbd995a94744a1370f01e2
parent354b4afba1ddd1f86fb587da0c74388df89dbc28 (diff)
downloadgitbook-793600ab2fe3923062b06dd25e59655805882409.zip
gitbook-793600ab2fe3923062b06dd25e59655805882409.tar.gz
gitbook-793600ab2fe3923062b06dd25e59655805882409.tar.bz2
Improve test to test a all book
-rw-r--r--lib/book.js11
-rw-r--r--test/fixtures/summary/markdown/SUMMARY.md11
-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/helper.js19
-rw-r--r--test/parsing.js14
-rw-r--r--test/summary.js22
9 files changed, 59 insertions, 37 deletions
diff --git a/lib/book.js b/lib/book.js
index f920100..5335896 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -128,13 +128,16 @@ Book.prototype.parseLangs = function() {
Book.prototype.parseSummary = function() {
var that = this;
- return that.findFile(that.config.getStructure("summary"))
- .then(function(summary) {
+ return Q.all([
+ that.findFile(that.config.getStructure("summary")),
+ that.findFile(that.config.getStructure("readme"))
+ ])
+ .spread(function(summary, readme) {
if (!summary) throw "No SUMMARY file";
return that.template.renderFile(summary.path)
.then(function(content) {
- return summary.parser.summary(content);
+ return summary.parser.summary(content, readme.path);
});
})
.then(function(summary) {
@@ -156,7 +159,7 @@ Book.prototype.parseGlossary = function() {
});
})
.then(function(glossary) {
- that.glossary = glossaryy;
+ that.glossary = glossary;
});
};
diff --git a/test/fixtures/summary/markdown/SUMMARY.md b/test/fixtures/summary/markdown/SUMMARY.md
deleted file mode 100644
index a51deae..0000000
--- a/test/fixtures/summary/markdown/SUMMARY.md
+++ /dev/null
@@ -1,11 +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)
-
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..4adaf3e
--- /dev/null
+++ b/test/fixtures/test1/SUMMARY.md
@@ -0,0 +1,6 @@
+# Summary
+
+* [Chapter 1](test.md)
+ * [Article 1](test1.md)
+* [Chapter 2](test2.md)
+
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/helper.js b/test/helper.js
new file mode 100644
index 0000000..f80edcb
--- /dev/null
+++ b/test/helper.js
@@ -0,0 +1,19 @@
+var path = require('path');
+var Q = require('q');
+var Book = require('../').Book;
+
+// Nicety for mocha / Q
+global.qdone = function qdone(promise, done) {
+ return promise.then(function() {
+ return done();
+ }, function(err) {
+ return done(err);
+ }).done();
+};
+
+// Init before doing tests
+before(function(done) {
+ global.book1 = new Book(path.join(__dirname, './fixtures/test1'));
+
+ qdone(global.book1.init(), done);
+});
diff --git a/test/parsing.js b/test/parsing.js
new file mode 100644
index 0000000..3d41939
--- /dev/null
+++ b/test/parsing.js
@@ -0,0 +1,14 @@
+var path = require('path');
+var assert = require('assert');
+
+var Book = require('../').Book;
+
+describe('Book parsing', function () {
+ it('should correctly parse it from markdown', function() {
+ var LEXED = book1.summary;
+
+ assert.equal(LEXED.chapters[0].path,'intro.md');
+ assert.equal(LEXED.chapters[1].path,'test.md');
+ assert.equal(LEXED.chapters[2].path,'test2.md');
+ });
+});
diff --git a/test/summary.js b/test/summary.js
deleted file mode 100644
index a90212f..0000000
--- a/test/summary.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var path = require('path');
-var assert = require('assert');
-
-var Book = require('../').Book;
-
-describe('Summary parsing', function () {
- it('should correctly parse it from markdown', function(done) {
- var book = new Book(path.join(__dirname, './fixtures/summary/markdown'));
- book.parseSummary()
- .then(function() {
- var LEXED = book.summary;
-
- 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');
- })
- .then(function() {
- done()
- }, done);
- });
-});