diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/assertions.js | 34 | ||||
-rw-r--r-- | test/plugins.js | 31 | ||||
-rw-r--r-- | test/plugins/config/index.js | 1 | ||||
-rw-r--r-- | test/plugins/config/package.json | 21 |
4 files changed, 71 insertions, 16 deletions
diff --git a/test/assertions.js b/test/assertions.js index 7e14ecb..f9c4ba3 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -1,27 +1,29 @@ -var _ = require("lodash"); -var fs = require("fs"); -var path = require("path"); -var should = require("should"); -var cheerio = require("cheerio"); +var _ = require('lodash'); +var fs = require('fs'); +var path = require('path'); +var should = require('should'); +var cheerio = require('cheerio'); -should.Assertion.add("file", function(file, description) { - this.params = { actual: this.obj.toString(), operator: "have file " + file, message: description }; +require('should-promised'); - this.obj.should.have.property("options").which.is.an.Object(); - this.obj.options.should.have.property("output").which.is.a.String(); +should.Assertion.add('file', function(file, description) { + this.params = { actual: this.obj.toString(), operator: 'have file ' + 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(fs.existsSync(path.resolve(this.obj.options.output, file))); }); -should.Assertion.add("jsonfile", function(file, description) { - this.params = { actual: this.obj.toString(), operator: "have valid jsonfile " + file, message: description }; +should.Assertion.add('jsonfile', function(file, description) { + this.params = { actual: this.obj.toString(), 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" }))); + 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' }))); }); -should.Assertion.add("html", function(rules, description) { - this.params = { actual: "HTML string", operator: "valid html", message: description }; +should.Assertion.add('html', function(rules, description) { + this.params = { actual: 'HTML string', operator: 'valid html', message: description }; var $ = cheerio.load(this.obj); _.each(rules, function(validations, query) { diff --git a/test/plugins.js b/test/plugins.js index 4f91e9a..db2d225 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -51,6 +51,37 @@ describe('Plugins', function () { }); }); + describe('Configuration', function() { + var plugin; + + before(function() { + plugin = new Plugin(book, 'testconfig'); + plugin.load('./config', PLUGINS_ROOT); + }); + + it('should throw error for invalid configuration', function() { + return plugin.validateConfig({}) + .should.be.rejectedWith('Configuration Error: pluginsConfig.testconfig.testRequired is required'); + }); + + it('should throw error for invalid types', function() { + return plugin.validateConfig({ + testRequired: 'hello' + }) + .should.be.rejectedWith('Configuration Error: pluginsConfig.testconfig.testRequired is not of a type(s) number'); + }); + + it('should extend with default values', function() { + return plugin.validateConfig({ + testRequired: 12 + }) + .should.be.fulfilledWith({ + hello: 'world', + testRequired: 12 + }); + }); + }); + describe('Resources', function() { var plugin; diff --git a/test/plugins/config/index.js b/test/plugins/config/index.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/test/plugins/config/index.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/test/plugins/config/package.json b/test/plugins/config/package.json new file mode 100644 index 0000000..03ef744 --- /dev/null +++ b/test/plugins/config/package.json @@ -0,0 +1,21 @@ +{ + "name": "gitbook-plugin-testconfig", + "description": "Test plugin configuration", + "main": "index.js", + "version": "0.0.1", + "engines": { + "gitbook": "*" + }, + "gitbook": { + "properties": { + "hello": { + "type": "string", + "default": "world" + }, + "testRequired": { + "type": "number", + "required": true + } + } + } +}
\ No newline at end of file |