Add test for parsing glossary

This commit is contained in:
Samy Pesse
2016-04-26 11:00:36 +02:00
parent 374ebd6f7a
commit 8a3f80ba82
5 changed files with 54 additions and 2 deletions
+6
View File
@@ -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 -1
View File
@@ -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() {
+9
View File
@@ -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')
+37
View File
@@ -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();
});
});
});
-1
View File
@@ -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);