summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-03-23 23:48:46 +0100
committerSamy Pessé <samypesse@gmail.com>2015-03-23 23:48:46 +0100
commitec8d1d8fc919f1a2918ccc5abf04033139f2cb53 (patch)
tree05e65c8920ade0546ebc4bb5d907705853a7a851 /test
parent868a3186dd40e57ec1c38174be1db28dfd4c85c4 (diff)
downloadgitbook-ec8d1d8fc919f1a2918ccc5abf04033139f2cb53.zip
gitbook-ec8d1d8fc919f1a2918ccc5abf04033139f2cb53.tar.gz
gitbook-ec8d1d8fc919f1a2918ccc5abf04033139f2cb53.tar.bz2
Improve test for json format
Diffstat (limited to 'test')
-rw-r--r--test/assertions.js8
-rw-r--r--test/json.js41
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);
+ });
+ });
});
});