summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2015-09-12 18:21:35 +0200
committerSamy Pesse <samypesse@gmail.com>2015-09-12 18:21:35 +0200
commit82a6ee3875bca2b068d76ccc894c4313d1006b77 (patch)
tree0ad9e753629774333ec163f21234fc770c10a541
parent3bf592f870eb24d1b4753fa538bad2cbfaa98a24 (diff)
downloadgitbook-82a6ee3875bca2b068d76ccc894c4313d1006b77.zip
gitbook-82a6ee3875bca2b068d76ccc894c4313d1006b77.tar.gz
gitbook-82a6ee3875bca2b068d76ccc894c4313d1006b77.tar.bz2
Add test for replacing highlighting
-rw-r--r--test/books/basic/README.md4
-rw-r--r--test/helper.js10
-rw-r--r--test/plugins.js27
-rw-r--r--test/plugins/highlight/index.js9
-rw-r--r--test/plugins/highlight/package.json9
5 files changed, 58 insertions, 1 deletions
diff --git a/test/books/basic/README.md b/test/books/basic/README.md
index 09ade40..73d74c0 100644
--- a/test/books/basic/README.md
+++ b/test/books/basic/README.md
@@ -1,3 +1,7 @@
# Readme
Default description for the book.
+
+```
+test
+```
diff --git a/test/helper.js b/test/helper.js
index f6b671b..ef5c45c 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -17,9 +17,17 @@ var TMPDIR = os.tmpdir();
// Generate and return a book
-function generateBook(bookId, test) {
+function generateBook(bookId, test, options) {
+ options = _.defaults(options || {}, {
+ before: function() {}
+ });
+
return parseBook(bookId, test)
.then(function(book) {
+ return Q(options.before(book))
+ .thenResolve(book);
+ })
+ .then(function(book) {
return book.generate(test)
.thenResolve(book);
});
diff --git a/test/plugins.js b/test/plugins.js
index d10e0b5..a81110c 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -1,6 +1,7 @@
var _ = require('lodash');
var should = require('should');
var path = require('path');
+var fs = require('fs');
var Plugin = require('../lib/plugin');
var parsers = require("gitbook-parsers");
@@ -234,5 +235,31 @@ describe('Plugins', function () {
});
});
});
+
+ describe('Replace code highlighting', function() {
+ it('should correctly replace highlighting', function() {
+ return books.generate('basic', 'website', {
+ before: function(book) {
+ var plugin = new Plugin(book, "blocks");
+ plugin.load("./highlight", PLUGINS_ROOT);
+
+ return book.plugins.load(plugin);
+ }
+ })
+ .then(function() {
+ var PAGE = fs.readFileSync(
+ path.join(book.options.output, "index.html"),
+ { encoding: "utf-8" }
+ );
+
+ PAGE.should.be.html({
+ "code": {
+ count: 1,
+ text: 'code__test\n__code'
+ }
+ });
+ });
+ })
+ });
});
diff --git a/test/plugins/highlight/index.js b/test/plugins/highlight/index.js
new file mode 100644
index 0000000..01202f2
--- /dev/null
+++ b/test/plugins/highlight/index.js
@@ -0,0 +1,9 @@
+module.exports = {
+ blocks: {
+ "code": {
+ process: function(blk) {
+ return "code_"+blk.body+"_code";
+ }
+ }
+ }
+}; \ No newline at end of file
diff --git a/test/plugins/highlight/package.json b/test/plugins/highlight/package.json
new file mode 100644
index 0000000..6b69488
--- /dev/null
+++ b/test/plugins/highlight/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "gitbook-plugin-highlight",
+ "description": "Highlight coe blocks",
+ "main": "index.js",
+ "version": "0.0.1",
+ "engines": {
+ "gitbook": "*"
+ }
+} \ No newline at end of file