mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-29 13:39:11 +00:00
Add test for parsing glossary
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
var Immutable = require('immutable');
|
||||
var jsonSchemaDefaults = require('json-schema-defaults');
|
||||
|
||||
var schema = require('./configSchema');
|
||||
|
||||
module.exports = Immutable.fromJS(jsonSchemaDefaults(schema));
|
||||
@@ -2,10 +2,11 @@ var is = require('is');
|
||||
var Immutable = require('immutable');
|
||||
|
||||
var File = require('./file');
|
||||
var configDefault = require('../constants/configDefault');
|
||||
|
||||
var Config = Immutable.Record({
|
||||
file: File(),
|
||||
values: Immutable.Map()
|
||||
values: configDefault
|
||||
}, 'Config');
|
||||
|
||||
Config.prototype.getPath = function() {
|
||||
|
||||
@@ -19,6 +19,15 @@ File.prototype.getMTime = function() {
|
||||
return this.get('mtime');
|
||||
};
|
||||
|
||||
/**
|
||||
Does the file exists / is set
|
||||
|
||||
@return {Boolean}
|
||||
*/
|
||||
File.prototype.exists = function() {
|
||||
return Boolean(this.getPath());
|
||||
};
|
||||
|
||||
/**
|
||||
Return type of file ('markdown' or 'asciidoc')
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
jest.autoMockOff();
|
||||
|
||||
describe('parseGlossary', function() {
|
||||
var parseGlossary = require('../parseGlossary');
|
||||
var Book = require('../../models/book');
|
||||
var createMockFS = require('../../fs/mock');
|
||||
|
||||
pit('should parse glossary if exists', function() {
|
||||
var fs = createMockFS({
|
||||
'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello'
|
||||
});
|
||||
var book = Book.createForFS(fs);
|
||||
|
||||
return parseGlossary(book)
|
||||
.then(function(resultBook) {
|
||||
var glossary = resultBook.getGlossary();
|
||||
var file = glossary.getFile();
|
||||
var entries = glossary.getEntries();
|
||||
|
||||
expect(file.exists()).toBeTruthy();
|
||||
expect(entries.size).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
pit('should not fail if doesn\'t exist', function() {
|
||||
var fs = createMockFS({});
|
||||
var book = Book.createForFS(fs);
|
||||
|
||||
return parseGlossary(book)
|
||||
.then(function(resultBook) {
|
||||
var glossary = resultBook.getGlossary();
|
||||
var file = glossary.getFile();
|
||||
|
||||
expect(file.exists()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -16,7 +16,6 @@ function parseGlossary(book) {
|
||||
return book;
|
||||
}
|
||||
|
||||
|
||||
logger.debug.ln('glossary index file found at', file.getPath());
|
||||
|
||||
var glossary = Glossary.createFromEntries(file, entries);
|
||||
|
||||
Reference in New Issue
Block a user