From 0b3bdcb2193e10f5bf0f6959475563d8c430aa40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 22 Feb 2016 15:39:36 +0100 Subject: [PATCH] Add tests for blocks from plugins --- .../gitbook-plugin-test-blocks/index.js | 21 ++++++++++++++ .../gitbook-plugin-test-blocks/package.json | 7 +++++ test/plugins.js | 28 +++++++++++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 test/node_modules/gitbook-plugin-test-blocks/index.js create mode 100644 test/node_modules/gitbook-plugin-test-blocks/package.json diff --git a/test/node_modules/gitbook-plugin-test-blocks/index.js b/test/node_modules/gitbook-plugin-test-blocks/index.js new file mode 100644 index 000000000..710400602 --- /dev/null +++ b/test/node_modules/gitbook-plugin-test-blocks/index.js @@ -0,0 +1,21 @@ +var should = require('should'); + +module.exports = { + blocks: { + // Simple test + hello: function(blk) { + return 'Hello ' + blk.body + '!'; + }, + + // Test using the conetxt "this" + testContext: function(s) { + this.should.have.property('config'); + this.should.have.property('log'); + this.should.have.property('options'); + this.should.have.property('resolve').which.is.a.function; + this.should.have.property('book').which.equal(this); + + return 'Hello ' + s + '!'; + } + } +}; diff --git a/test/node_modules/gitbook-plugin-test-blocks/package.json b/test/node_modules/gitbook-plugin-test-blocks/package.json new file mode 100644 index 000000000..a756fb515 --- /dev/null +++ b/test/node_modules/gitbook-plugin-test-blocks/package.json @@ -0,0 +1,7 @@ +{ + "name": "gitbook-plugin-test-blocks", + "version": "1.0.0", + "engines": { + "gitbook": "*" + } +} \ No newline at end of file diff --git a/test/plugins.js b/test/plugins.js index 03bbc266b..8207663ba 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -138,8 +138,7 @@ describe('Plugins', function() { }); }); - - it('should list all resources for website', function() { + it('should list all filters', function() { _.size(filters).should.equal(2); }); @@ -151,5 +150,30 @@ describe('Plugins', function() { filters.testContext('Hello'); }); }); + + describe('Blocks', function() { + var plugin, blocks; + + before(function() { + plugin = new BookPlugin(book, 'test-blocks'); + return plugin.load(PLUGINS_ROOT) + + .then(function() { + blocks = plugin.getBlocks(); + }); + }); + + it('should list all blocks', function() { + _.size(blocks).should.equal(2); + }); + + it('should correctly normalize block', function() { + blocks.hello.exec({ body: 'World' }).should.equal('Hello World!'); + }); + + it('should correctly set contexts for filter', function() { + blocks.testContext.exec({ body: 'Hello' }); + }); + }); });