diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/assertions.js | 8 | ||||
-rw-r--r-- | test/json.js | 41 |
2 files changed, 46 insertions, 3 deletions
diff --git a/test/assertions.js b/test/assertions.js index b40a518..a1c2eb9 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -9,3 +9,11 @@ should.Assertion.add('file', function(file, description) { this.obj.options.should.have.property('output').which.is.a.String; this.assert(fs.existsSync(path.resolve(this.obj.options.output, file))); }); + +should.Assertion.add('jsonfile', function(file, description) { + this.params = { operator: 'have valid jsonfile ' + file, message: description }; + + this.obj.should.have.property('options').which.is.an.Object; + this.obj.options.should.have.property('output').which.is.a.String; + this.assert(JSON.parse(fs.readFileSync(path.resolve(this.obj.options.output, file), { encoding: "utf-8" }))); +}); diff --git a/test/json.js b/test/json.js index 7bebd4c..3ee2066 100644 --- a/test/json.js +++ b/test/json.js @@ -1,11 +1,46 @@ +var fs = require('fs'); +var path = require('path'); describe('JSON generator', function () { describe('Basic Book', function() { - it('should correctly output a README.json', function() { + var book; + + before(function() { return books.generate("basic", "json") - .then(function(book) { - book.should.have.file("README.json"); + .then(function(_book) { + book = _book; }); }); + + it('should correctly output a README.json', function() { + book.should.have.file("README.json"); + }); + + it('should output a valid json', function() { + book.should.have.jsonfile("README.json"); + }); + + describe('Page Format', function() { + var page; + + before(function() { + page = JSON.parse( + fs.readFileSync( + path.join(book.options.output, "README.json"), + { encoding: "utf-8" } + ) + ); + }); + + it('should contains valid section', function() { + page.should.have.property("sections").with.lengthOf(1); + page.sections[0].should.have.property("content").which.is.a.String; + page.sections[0].should.have.property("type").which.is.a.String.which.equal("normal"); + }); + + it('should contains no languages', function() { + page.should.have.property("langs").with.lengthOf(0); + }); + }); }); }); |