diff options
-rw-r--r-- | test/configuration.js | 22 | ||||
-rw-r--r-- | test/fixtures/test0/README.md | 3 | ||||
-rw-r--r-- | test/fixtures/test0/SUMMARY.md | 1 | ||||
-rw-r--r-- | test/fixtures/test0/book.json (renamed from test/fixtures/configuration/json/book.json) | 0 | ||||
-rw-r--r-- | test/fixtures/test4/README.md | 3 | ||||
-rw-r--r-- | test/fixtures/test4/SUMMARY.md | 1 | ||||
-rw-r--r-- | test/fixtures/test4/book.js (renamed from test/fixtures/configuration/js/book.js) | 0 | ||||
-rw-r--r-- | test/generation.js | 22 | ||||
-rw-r--r-- | test/helper.js | 31 | ||||
-rw-r--r-- | test/parsing.js | 28 |
10 files changed, 58 insertions, 53 deletions
diff --git a/test/configuration.js b/test/configuration.js index 57bead9..e690f2c 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -4,25 +4,11 @@ var assert = require('assert'); var Book = require('../').Book; describe('Configuration parsing', function () { - it('should correctly load from json', function(done) { - var book = new Book(path.join(__dirname, './fixtures/configuration/json')); - book.config.load() - .then(function() { - assert(book.options.title == "Test"); - }) - .then(function() { - done() - }, done); + it('should correctly load from json', function() { + assert(books[0].options.title == "Test"); }); - it('should correctly load from javascript', function(done) { - var book = new Book(path.join(__dirname, './fixtures/configuration/js')); - book.config.load() - .then(function() { - assert(book.options.title == "Test 2"); - }) - .then(function() { - done() - }, done); + it('should correctly load from javascript', function() { + assert(books[4].options.title == "Test 2"); }); }); diff --git a/test/fixtures/test0/README.md b/test/fixtures/test0/README.md new file mode 100644 index 0000000..d26ab9b --- /dev/null +++ b/test/fixtures/test0/README.md @@ -0,0 +1,3 @@ +# Other Title + +A description 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/configuration/json/book.json b/test/fixtures/test0/book.json index a2191b8..a2191b8 100644 --- a/test/fixtures/configuration/json/book.json +++ b/test/fixtures/test0/book.json diff --git a/test/fixtures/test4/README.md b/test/fixtures/test4/README.md new file mode 100644 index 0000000..d26ab9b --- /dev/null +++ b/test/fixtures/test4/README.md @@ -0,0 +1,3 @@ +# Other Title + +A description diff --git a/test/fixtures/test4/SUMMARY.md b/test/fixtures/test4/SUMMARY.md new file mode 100644 index 0000000..ac9323c --- /dev/null +++ b/test/fixtures/test4/SUMMARY.md @@ -0,0 +1 @@ +# Summary diff --git a/test/fixtures/configuration/js/book.js b/test/fixtures/test4/book.js index bf617cd..bf617cd 100644 --- a/test/fixtures/configuration/js/book.js +++ b/test/fixtures/test4/book.js diff --git a/test/generation.js b/test/generation.js index d2d0574..1d73068 100644 --- a/test/generation.js +++ b/test/generation.js @@ -22,7 +22,7 @@ var testGeneration = function(book, type, func, done) { describe('Book generation', function () { it('should correctly generate a book to json', function(done) { - testGeneration(book1, "json", function(output) { + 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"))); @@ -32,25 +32,25 @@ describe('Book generation', function () { }, done); }); - it('should correctly generate an asciidoc book to json', function(done) { - testGeneration(book3, "json", function(output) { + 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, "test.json"))); - assert(fs.existsSync(path.join(output, "test1.json"))); - assert(fs.existsSync(path.join(output, "test2.json"))); + assert(fs.existsSync(path.join(output, "en/README.json"))); + assert(fs.existsSync(path.join(output, "fr/README.json"))); }, done); }); - it('should correctly generate a multilingual book to json', function(done) { - testGeneration(book2, "json", function(output) { + 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, "en/README.json"))); - assert(fs.existsSync(path.join(output, "fr/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 to website', function(done) { - testGeneration(book1, "site", function(output) { + testGeneration(books[1], "site", function(output) { assert(fs.existsSync(path.join(output, "index.html"))); }, done); }); diff --git a/test/helper.js b/test/helper.js index f29b3c7..27d5f01 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,5 +1,8 @@ var path = require('path'); var Q = require('q'); +var fs = require('fs'); +var _ = require('lodash'); + var Book = require('../').Book; // Nicety for mocha / Q @@ -11,20 +14,28 @@ global.qdone = function qdone(promise, done) { }).done(); }; +// Books for testings +global.books = []; + // Init before doing tests before(function(done) { - global.book1 = new Book(path.join(__dirname, './fixtures/test1')); - global.book2 = new Book(path.join(__dirname, './fixtures/test2')); - global.book3 = new Book(path.join(__dirname, './fixtures/test3')); + 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));; + }) + .compact() + .value(); qdone( - global.book1.parse() - .then(function() { - return global.book2.parse(); - }) - .then(function() { - return global.book3.parse(); - }), + _.reduce(global.books, function(prev, book) { + return prev.then(function() { + return book.parse(); + }); + }, Q()), done ); }); diff --git a/test/parsing.js b/test/parsing.js index 7be50cd..f61a4fe 100644 --- a/test/parsing.js +++ b/test/parsing.js @@ -4,17 +4,17 @@ var assert = require('assert'); describe('Book parsing', function () { it('should correctly parse the readme', function() { - assert.equal(book1.options.title, 'My Book'); - assert.equal(book1.options.description, 'Test description'); + 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(book3.options.title, 'My Book'); - assert.equal(book3.options.description, 'Test description'); + 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 = book1.summary; + var LEXED = books[1].summary; assert.equal(LEXED.chapters[0].path, 'intro.md'); assert.equal(LEXED.chapters[1].path, 'test.md'); @@ -22,7 +22,7 @@ describe('Book parsing', function () { }); it('should correctly parse the glossary', function() { - var LEXED = book1.glossary; + var LEXED = books[1].glossary; assert.equal(LEXED[0].id, "test"); assert.equal(LEXED[0].name, "Test"); @@ -34,24 +34,24 @@ describe('Book parsing', function () { }); it('should correctly parse list of files', function() { - var FILES = book1.files; + 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(book2.books.length, 2); - assert(book2.isMultilingual()); + assert.equal(books[2].books.length, 2); + assert(books[2].isMultilingual()); - assert.equal(book2.books[0].options.lang, "en"); - assert.equal(book2.books[0].options.title, "English Book"); + assert.equal(books[2].books[0].options.lang, "en"); + assert.equal(books[2].books[0].options.title, "English Book"); - assert.equal(book2.books[1].options.lang, "fr"); - assert.equal(book2.books[1].options.title, "French Book"); + assert.equal(books[2].books[1].options.lang, "fr"); + assert.equal(books[2].books[1].options.title, "French Book"); }); it('should correctly parse the navigation', function() { - var NAVIGATION = book1.navigation; + var NAVIGATION = books[1].navigation; assert.equal(_.size(NAVIGATION), 2); assert(NAVIGATION["intro.md"]) |