summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-23 15:05:32 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-23 15:05:32 +0100
commitf052aacee1140f211ebb9454157fa7a3604005cf (patch)
treef784d8b9fd70bd94b754e13d26e6f6dd548b9908 /test
parent13e2ff8035d9a93e4ee8eb79ec71ac92e6f2bf7e (diff)
downloadgitbook-f052aacee1140f211ebb9454157fa7a3604005cf.zip
gitbook-f052aacee1140f211ebb9454157fa7a3604005cf.tar.gz
gitbook-f052aacee1140f211ebb9454157fa7a3604005cf.tar.bz2
Add .gitbook to locate book inside repository
Diffstat (limited to 'test')
-rw-r--r--test/all.js1
-rw-r--r--test/locate.js28
-rw-r--r--test/mock.js48
3 files changed, 54 insertions, 23 deletions
diff --git a/test/all.js b/test/all.js
index 5a96e38..9c82c91 100644
--- a/test/all.js
+++ b/test/all.js
@@ -4,6 +4,7 @@ require('./location');
require('./paths');
// Parsing
+require('./locate');
require('./config');
require('./readme');
require('./summary');
diff --git a/test/locate.js b/test/locate.js
new file mode 100644
index 0000000..609f2da
--- /dev/null
+++ b/test/locate.js
@@ -0,0 +1,28 @@
+var path = require('path');
+
+var Book = require('../').Book;
+var mock = require('./mock');
+
+describe('Locate', function() {
+ it('should use root folder if no .gitbook', function() {
+ return mock.setupFS({
+ 'README.md': '# Hello'
+ })
+ .then(function(root) {
+ return Book.locate(mock.fs, root)
+ .should.be.fulfilledWith(root);
+ });
+ });
+
+ it('should use resolve using .gitbook', function() {
+ return mock.setupFS({
+ 'README.md': '# Hello',
+ '.gitbook': './docs'
+ })
+ .then(function(root) {
+ return Book.locate(mock.fs, root)
+ .should.be.fulfilledWith(path.resolve(root, 'docs'));
+ });
+ });
+
+});
diff --git a/test/mock.js b/test/mock.js
index b075f2c..1bb92e2 100644
--- a/test/mock.js
+++ b/test/mock.js
@@ -14,27 +14,30 @@ require('./assertions');
// Create filesystem instance for testing
var nodeFS = new NodeFS();
-function setupFS(_fs, rootFolder, files) {
- return _.chain(_.pairs(files))
- .sortBy(0)
- .reduce(function(prev, pair) {
- return prev.then(function() {
- var filename = path.resolve(rootFolder, pair[0]);
- var buf = pair[1];
-
- if (_.isObject(buf)) buf = JSON.stringify(buf);
- if (_.isString(buf)) buf = new Buffer(buf, 'utf-8');
-
- return fs.mkdirp(path.dirname(filename))
- .then(function() {
- return fs.writeFile(filename, buf);
+function setupFS(files) {
+ return Q.nfcall(tmp.dir.bind(tmp)).get(0)
+ .then(function(rootFolder) {
+ return _.chain(_.pairs(files))
+ .sortBy(0)
+ .reduce(function(prev, pair) {
+ return prev.then(function() {
+ var filename = path.resolve(rootFolder, pair[0]);
+ var buf = pair[1];
+
+ if (_.isObject(buf)) buf = JSON.stringify(buf);
+ if (_.isString(buf)) buf = new Buffer(buf, 'utf-8');
+
+ return fs.mkdirp(path.dirname(filename))
+ .then(function() {
+ return fs.writeFile(filename, buf);
+ });
});
+ }, Q())
+ .value()
+ .then(function() {
+ return rootFolder;
});
- }, Q())
- .value()
- .then(function() {
- return _fs;
- });
+ });
}
// Setup a mock book for testing using a map of files
@@ -42,14 +45,11 @@ function setupBook(files, opts) {
opts = opts || {};
opts.log = function() { };
- return Q.nfcall(tmp.dir.bind(tmp)).get(0)
+ return setupFS(files)
.then(function(folder) {
opts.fs = nodeFS;
opts.root = folder;
- return setupFS(nodeFS, folder, files);
- })
- .then(function() {
return new Book(opts);
});
}
@@ -90,6 +90,8 @@ function logError(err) {
}
module.exports = {
+ fs: nodeFS,
+ setupFS: setupFS,
setupBook: setupBook,
setupDefaultBook: setupDefaultBook,
outputDefaultBook: outputDefaultBook,