summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/configuration.js34
-rw-r--r--test/format.js11
-rw-r--r--test/init.js26
-rw-r--r--test/plugins.js198
4 files changed, 140 insertions, 129 deletions
diff --git a/test/configuration.js b/test/configuration.js
index c96c10d..d30fd61 100644
--- a/test/configuration.js
+++ b/test/configuration.js
@@ -1,37 +1,37 @@
-describe("Configuration", function () {
- it("should extract default title from README", function() {
- return books.parse("basic")
+describe('Configuration', function () {
+ it('should extract default title from README', function() {
+ return books.parse('basic')
.then(function(book) {
- book.options.title.should.be.equal("Readme");
+ book.options.title.should.be.equal('Readme');
});
});
- it("should extract default description from README", function() {
- return books.parse("basic")
+ it('should extract default description from README', function() {
+ return books.parse('basic')
.then(function(book) {
- book.options.description.should.be.equal("Default description for the book.");
+ book.options.description.should.be.equal('Default description for the book.');
});
});
- it("should correctly load from json (book.json)", function() {
- return books.parse("config-json")
+ it('should correctly load from json (book.json)', function() {
+ return books.parse('config-json')
.then(function(book) {
- book.options.title.should.be.equal("json-config");
+ book.options.title.should.be.equal('json-config');
});
});
- it("should correctly load from JavaScript (book.js)", function() {
- return books.parse("config-js")
+ it('should correctly load from JavaScript (book.js)', function() {
+ return books.parse('config-js')
.then(function(book) {
- book.options.title.should.be.equal("js-config");
+ book.options.title.should.be.equal('js-config');
});
});
- it("should provide configuration on book.config.get", function() {
- return books.parse("basic")
+ it('should provide configuration on book.config.get', function() {
+ return books.parse('basic')
.then(function(book) {
- book.config.get("description").should.be.equal("Default description for the book.");
- book.getConfig("description").should.be.equal("Default description for the book.");
+ book.config.get('description').should.be.equal('Default description for the book.');
+ book.getConfig('description').should.be.equal('Default description for the book.');
});
});
});
diff --git a/test/format.js b/test/format.js
new file mode 100644
index 0000000..2ec1a6f
--- /dev/null
+++ b/test/format.js
@@ -0,0 +1,11 @@
+describe('Formatting', function () {
+ it('should provide formatting with book.formatString', function() {
+ return books.parse('basic')
+ .then(function(book) {
+ return book.formatString('markdown', 'this is a **test**');
+ })
+ .then(function(content) {
+ content.should.equal('<p>this is a <strong>test</strong></p>\n');
+ });
+ });
+});
diff --git a/test/init.js b/test/init.js
index 7e5ffee..625d77c 100644
--- a/test/init.js
+++ b/test/init.js
@@ -1,24 +1,24 @@
-var fs = require("fs");
-var path = require("path");
-var should = require("should");
+var fs = require('fs');
+var path = require('path');
+var should = require('should');
-var Book = require("../").Book;
-var LOG_LEVELS = require("../").LOG_LEVELS;
+var Book = require('../').Book;
+var LOG_LEVELS = require('../').LOG_LEVELS;
-describe("Init Books", function () {
+describe('Init Books', function () {
var initRoot;
before(function() {
- initRoot = path.resolve(__dirname, "books/init");
+ initRoot = path.resolve(__dirname, 'books/init');
return Book.init(initRoot, {
- logLevel: LOG_LEVELS.DISABLED,
+ logLevel: LOG_LEVELS.DISABLED
});
});
- it("should create all chapters", function() {
- should(fs.existsSync(path.resolve(initRoot, "hello.md"))).be.ok();
- should(fs.existsSync(path.resolve(initRoot, "hello2.md"))).be.ok();
- should(fs.existsSync(path.resolve(initRoot, "hello3/hello4.md"))).be.ok();
- should(fs.existsSync(path.resolve(initRoot, "hello3/hello5/hello6.md"))).be.ok();
+ it('should create all chapters', function() {
+ should(fs.existsSync(path.resolve(initRoot, 'hello.md'))).be.ok();
+ should(fs.existsSync(path.resolve(initRoot, 'hello2.md'))).be.ok();
+ should(fs.existsSync(path.resolve(initRoot, 'hello3/hello4.md'))).be.ok();
+ should(fs.existsSync(path.resolve(initRoot, 'hello3/hello5/hello6.md'))).be.ok();
});
});
diff --git a/test/plugins.js b/test/plugins.js
index 797fc38..c0f2373 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -1,47 +1,47 @@
-var _ = require("lodash");
-var should = require("should");
-var path = require("path");
+var _ = require('lodash');
+var should = require('should');
+var path = require('path');
-var Plugin = require("../lib/plugin");
-var parsers = require("gitbook-parsers");
-var PLUGINS_ROOT = path.resolve(__dirname, "plugins");
+var Plugin = require('../lib/plugin');
+var parsers = require('gitbook-parsers');
+var PLUGINS_ROOT = path.resolve(__dirname, 'plugins');
-describe("Plugins", function () {
+describe('Plugins', function () {
var book;
before(function() {
- return books.parse("basic")
- .then(function(_book) {
- book = _book;
- });
+ return books.parse('basic')
+ .then(function(_book) {
+ book = _book;
+ });
});
- describe("Invalid", function() {
+ describe('Invalid', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "invalid");
- plugin.load("./invalid", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'invalid');
+ plugin.load('./invalid', PLUGINS_ROOT);
});
- it("should be detected", function() {
+ it('should be detected', function() {
should(plugin.isValid()).be.exactly(false);
});
});
- describe("Empty", function() {
+ describe('Empty', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "empty");
- plugin.load("./empty", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'empty');
+ plugin.load('./empty', PLUGINS_ROOT);
});
- it("should valid a plugin", function() {
+ it('should valid a plugin', function() {
should(plugin.isValid()).be.exactly(true);
});
- it("should return an empty list of resources", function() {
+ it('should return an empty list of resources', function() {
return plugin.getResources()
.then(function(resources) {
_.each(Plugin.RESOURCES, function(resName) {
@@ -51,97 +51,97 @@ describe("Plugins", function () {
});
});
- describe("Resources", function() {
+ describe('Resources', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "resources");
- plugin.load("./resources", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'resources');
+ plugin.load('./resources', PLUGINS_ROOT);
return book.plugins.load(plugin);
});
- it("should valid a plugin", function() {
+ it('should valid a plugin', function() {
should(plugin.isValid()).be.exactly(true);
});
- describe("Website", function() {
- it("should return a valid list of resources", function() {
- return plugin.getResources("website")
+ describe('Website', function() {
+ it('should return a valid list of resources', function() {
+ return plugin.getResources('website')
.then(function(resources) {
resources.js.should.have.lengthOf(1);
});
});
- it("should extend books plugins", function() {
- var resources = book.plugins.resources("website");
- resources.js.should.have.lengthOf(1);
+ it('should extend books plugins', function() {
+ var resources = book.plugins.resources('website');
+ resources.js.should.have.lengthOf(5);
});
});
- describe("eBook", function() {
- it("should return a valid list of resources", function() {
- return plugin.getResources("ebook")
+ describe('eBook', function() {
+ it('should return a valid list of resources', function() {
+ return plugin.getResources('ebook')
.then(function(resources) {
resources.css.should.have.lengthOf(1);
});
});
- it("should extend books plugins", function() {
- var resources = book.plugins.resources("ebook");
+ it('should extend books plugins', function() {
+ var resources = book.plugins.resources('ebook');
// There is resources from highlight plugin and this plugin
resources.css.should.have.lengthOf(2);
should.exist(_.find(resources.css, {
- path: "./resources/test"
+ path: './resources/test'
}));
});
});
});
- describe("Filters", function() {
+ describe('Filters', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "filters");
- plugin.load("./filters", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'filters');
+ plugin.load('./filters', PLUGINS_ROOT);
return book.plugins.load(plugin);
});
- it("should valid a plugin", function() {
+ it('should valid a plugin', function() {
should(plugin.isValid()).be.exactly(true);
});
- it("should return a map of filters", function() {
+ it('should return a map of filters', function() {
var filters = plugin.getFilters();
_.size(filters).should.equal(2);
- filters.should.have.property("hello");
- filters.should.have.property("helloCtx");
+ filters.should.have.property('hello');
+ filters.should.have.property('helloCtx');
});
- it("should correctly extend template filters", function() {
- return book.template.renderString("{{ \"World\"|hello }}")
+ it('should correctly extend template filters', function() {
+ return book.template.renderString('{{ \'World\'|hello }}')
.then(function(content) {
- content.should.equal("Hello World");
+ content.should.equal('Hello World');
});
});
- it("should correctly set book as context", function() {
- return book.template.renderString("{{ \"root\"|helloCtx }}")
+ it('should correctly set book as context', function() {
+ return book.template.renderString('{{ \'root\'|helloCtx }}')
.then(function(content) {
- content.should.equal("root:"+book.root);
+ content.should.equal('root:'+book.root);
});
});
});
- describe("Blocks", function() {
+ describe('Blocks', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "blocks");
- plugin.load("./blocks", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'blocks');
+ plugin.load('./blocks', PLUGINS_ROOT);
return book.plugins.load(plugin);
});
@@ -151,89 +151,89 @@ describe("Plugins", function () {
.then(book.template.postProcess);
};
- it("should valid a plugin", function() {
+ it('should valid a plugin', function() {
should(plugin.isValid()).be.exactly(true);
});
- it("should correctly extend template blocks", function() {
- return testTpl("{% test %}hello{% endtest %}")
+ it('should correctly extend template blocks', function() {
+ return testTpl('{% test %}hello{% endtest %}')
.then(function(content) {
- content.should.equal("testhellotest");
+ content.should.equal('testhellotest');
});
});
- it("should correctly accept shortcuts", function() {
- return testTpl("$$hello$$", {}, {
- type: "markdown"
- })
- .then(function(content) {
- content.should.equal("testhellotest");
- });
+ it('should correctly accept shortcuts', function() {
+ return testTpl('$$hello$$', {}, {
+ type: 'markdown'
+ })
+ .then(function(content) {
+ content.should.equal('testhellotest');
+ });
});
- it("should correctly extend template blocks with defined end", function() {
- return testTpl("{% test2 %}hello{% endtest2end %}")
+ it('should correctly extend template blocks with defined end', function() {
+ return testTpl('{% test2 %}hello{% endtest2end %}')
.then(function(content) {
- content.should.equal("test2hellotest2");
+ content.should.equal('test2hellotest2');
});
});
- it("should correctly extend template blocks with sub-blocks", function() {
- return testTpl("{% test3join separator=\";\" %}hello{% also %}world{% endtest3join %}")
+ it('should correctly extend template blocks with sub-blocks', function() {
+ return testTpl('{% test3join separator=";" %}hello{% also %}world{% endtest3join %}')
.then(function(content) {
- content.should.equal("hello;world");
+ content.should.equal('hello;world');
});
});
- it("should correctly extend template blocks with different sub-blocks", function() {
- return testTpl("{% test4join separator=\";\" %}hello{% also %}the{% finally %}world{% endtest4join %}")
+ it('should correctly extend template blocks with different sub-blocks', function() {
+ return testTpl('{% test4join separator=";" %}hello{% also %}the{% finally %}world{% endtest4join %}')
.then(function(content) {
- content.should.equal("hello;the;world");
+ content.should.equal('hello;the;world');
});
});
- it("should correctly extend template blocks with arguments (1)", function() {
- return testTpl("{% test5args \"a\" %}{% endtest5args %}")
+ it('should correctly extend template blocks with arguments (1)', function() {
+ return testTpl('{% test5args "a" %}{% endtest5args %}')
.then(function(content) {
- content.should.equal("test5atest5");
+ content.should.equal('test5atest5');
});
});
- it("should correctly extend template blocks with arguments (2)", function() {
- return testTpl("{% test5args 'a', 'b' %}{% endtest5args %}")
+ it('should correctly extend template blocks with arguments (2)', function() {
+ return testTpl('{% test5args "a", "b" %}{% endtest5args %}')
.then(function(content) {
- content.should.equal("test5a,btest5");
+ content.should.equal('test5a,btest5');
});
});
- it("should correctly extend template blocks with arguments (3)", function() {
- return testTpl("{% test5args 'a', 'b', 'c' %}{% endtest5args %}")
+ it('should correctly extend template blocks with arguments (3)', function() {
+ return testTpl('{% test5args "a", "b", "c" %}{% endtest5args %}')
.then(function(content) {
- content.should.equal("test5a,b,ctest5");
+ content.should.equal('test5a,b,ctest5');
});
});
- it("should correctly extend template blocks with args and kwargs", function() {
- return testTpl("{% test5kwargs 'a', 'b', 'c', d='test', e='test2' %}{% endtest5kwargs %}")
+ it('should correctly extend template blocks with args and kwargs', function() {
+ return testTpl('{% test5kwargs "a", "b", "c", d="test", e="test2" %}{% endtest5kwargs %}')
.then(function(content) {
- content.should.equal("test5a,b,c,d:test,e:test2,__keywords:truetest5");
+ content.should.equal('test5a,b,c,d:test,e:test2,__keywords:truetest5');
});
});
- it("should correctly extend template blocks with access to context", function() {
- return testTpl("{% set name = 'john' %}{% test6context %}{% endtest6context %}", {})
- .then(function(content) {
- content.should.equal("test6johntest6");
- });
+ it('should correctly extend template blocks with access to context', function() {
+ return testTpl('{% set name = "john" %}{% test6context %}{% endtest6context %}', {})
+ .then(function(content) {
+ content.should.equal('test6johntest6');
+ });
});
});
- describe("Blocks without parsing", function() {
+ describe('Blocks without parsing', function() {
var plugin;
before(function() {
- plugin = new Plugin(book, "blocks");
- plugin.load("./blocks", PLUGINS_ROOT);
+ plugin = new Plugin(book, 'blocks');
+ plugin.load('./blocks', PLUGINS_ROOT);
return book.plugins.load(plugin);
});
@@ -242,21 +242,21 @@ describe("Plugins", function () {
var filetype = parsers.get(markup);
return book.template.renderString(str, args, options)
- .then(filetype.page).get("sections").get(0).get("content")
+ .then(filetype.page).get('sections').get(0).get('content')
.then(book.template.postProcess);
};
- it("should correctly process unparsable for markdown", function() {
- return testTpl(".md", "{% test %}**hello**{% endtest %}")
+ it('should correctly process unparsable for markdown', function() {
+ return testTpl('.md', '{% test %}**hello**{% endtest %}')
.then(function(content) {
- content.should.equal("<p>test**hello**test</p>\n");
+ content.should.equal('<p>test**hello**test</p>\n');
});
});
- it("should correctly process unparsable for asciidoc", function() {
- return testTpl(".adoc", "{% test %}**hello**{% endtest %}")
+ it('should correctly process unparsable for asciidoc', function() {
+ return testTpl('.adoc', '{% test %}**hello**{% endtest %}')
.then(function(content) {
- content.should.equal("<div class=\"paragraph\">\n<p>test**hello**test</p>\n</div>");
+ content.should.equal('<div class="paragraph">\n<p>test**hello**test</p>\n</div>');
});
});
});