Switch tests to mocha while keeping jest structure

This commit is contained in:
Samy Pesse
2016-05-11 13:02:20 +02:00
parent d5c4af3377
commit ef589a6b13
37 changed files with 226 additions and 155 deletions
-25
View File
@@ -1,25 +0,0 @@
var path = require('path');
var fs = require('fs');
var matchers = {
/**
Verify that a file exists in a directory
*/
toHaveFile: function () {
return {
compare: function (actual, expected) {
var filePath = path.join(actual, expected);
var exists = fs.existsSync(filePath);
return {
pass: exists
};
}
};
}
};
jasmine.getEnv().beforeEach(function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
jasmine.addMatchers(matchers);
});
+1 -1
View File
@@ -3,7 +3,7 @@ var initBook = require('../init');
describe('initBook', function() {
pit('should create a README and SUMMARY for empty book', function() {
it('should create a README and SUMMARY for empty book', function() {
var dir = tmp.dirSync();
return initBook(dir.name)
+9 -10
View File
@@ -1,7 +1,6 @@
jest.autoMockOff();
var createMockFS = require('../mock');
describe('MockFS', function() {
var createMockFS = require('../mock');
var fs = createMockFS({
'README.md': 'Hello World',
'SUMMARY.md': '# Summary',
@@ -15,35 +14,35 @@ describe('MockFS', function() {
});
describe('exists', function() {
pit('must return true for a file', function() {
it('must return true for a file', function() {
return fs.exists('README.md')
.then(function(result) {
expect(result).toBeTruthy();
});
});
pit('must return false for a non existing file', function() {
it('must return false for a non existing file', function() {
return fs.exists('README_NOTEXISTS.md')
.then(function(result) {
expect(result).toBeFalsy();
});
});
pit('must return true for a directory', function() {
it('must return true for a directory', function() {
return fs.exists('folder')
.then(function(result) {
expect(result).toBeTruthy();
});
});
pit('must return true for a deep file', function() {
it('must return true for a deep file', function() {
return fs.exists('folder/test.md')
.then(function(result) {
expect(result).toBeTruthy();
});
});
pit('must return true for a deep file (2)', function() {
it('must return true for a deep file (2)', function() {
return fs.exists('folder/folder2/hello.md')
.then(function(result) {
expect(result).toBeTruthy();
@@ -52,14 +51,14 @@ describe('MockFS', function() {
});
describe('readAsString', function() {
pit('must return content for a file', function() {
it('must return content for a file', function() {
return fs.readAsString('README.md')
.then(function(result) {
expect(result).toBe('Hello World');
});
});
pit('must return content for a deep file', function() {
it('must return content for a deep file', function() {
return fs.readAsString('folder/test.md')
.then(function(result) {
expect(result).toBe('Cool');
@@ -68,7 +67,7 @@ describe('MockFS', function() {
});
describe('readDir', function() {
pit('must return content for a directory', function() {
it('must return content for a directory', function() {
return fs.readDir('./')
.then(function(files) {
expect(files.size).toBe(3);
+1 -4
View File
@@ -1,10 +1,7 @@
jest.autoMockOff();
var Immutable = require('immutable');
var Config = require('../config');
describe('Config', function() {
var Config = require('../config');
var config = Config.createWithValues({
hello: {
world: 1,
+4 -6
View File
@@ -1,10 +1,8 @@
jest.autoMockOff();
var File = require('../file');
var Glossary = require('../glossary');
var GlossaryEntry = require('../glossaryEntry');
describe('Glossary', function() {
var File = require('../file');
var Glossary = require('../glossary');
var GlossaryEntry = require('../glossaryEntry');
var glossary = Glossary.createFromEntries(File(), [
{
name: 'Hello World',
@@ -30,7 +28,7 @@ describe('Glossary', function() {
});
describe('toText', function() {
pit('return as markdown', function() {
it('return as markdown', function() {
return glossary.toText('.md')
.then(function(text) {
expect(text).toContain('# Glossary');
+1 -3
View File
@@ -1,8 +1,6 @@
jest.autoMockOff();
var GlossaryEntry = require('../glossaryEntry');
describe('GlossaryEntry', function() {
var GlossaryEntry = require('../glossaryEntry');
describe('getID', function() {
it('must return a normalized ID', function() {
var entry = new GlossaryEntry({
+17 -2
View File
@@ -1,6 +1,7 @@
describe('PluginDependency', function() {
var PluginDependency = require('../pluginDependency');
var Immutable = require('immutable');
var PluginDependency = require('../pluginDependency');
describe('PluginDependency', function() {
describe('createFromString', function() {
it('must parse name', function() {
var plugin = PluginDependency.createFromString('hello');
@@ -42,6 +43,20 @@ describe('PluginDependency', function() {
});
});
});
describe('listToArray', function() {
var list = PluginDependency.listToArray(Immutable.List([
PluginDependency.createFromString('hello@1.0.0'),
PluginDependency.createFromString('noversion'),
PluginDependency.createFromString('-disabled')
]));
expect(list).toEqual([
'hello@1.0.0',
'noversion',
'-disabled'
]);
});
});
+1 -1
View File
@@ -82,7 +82,7 @@ describe('Summary', function() {
});
describe('toText', function() {
pit('return as markdown', function() {
it('return as markdown', function() {
return summary.toText('.md')
.then(function(text) {
expect(text).toContain('# Summary');
+7 -7
View File
@@ -6,7 +6,7 @@ describe('TemplateBlock', function() {
var TemplateBlock = require('../templateBlock');
describe('create', function() {
pit('must initialize a simple TemplateBlock from a function', function() {
it('must initialize a simple TemplateBlock from a function', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
return {
body: '<p>Hello, World!</p>',
@@ -41,7 +41,7 @@ describe('TemplateBlock', function() {
};
});
expect(templateBlock.getShortcuts()).not.toBeDefined();
expect(templateBlock.getShortcuts()).toNotExist();
});
it('must return complete shortcut', function() {
@@ -67,7 +67,7 @@ describe('TemplateBlock', function() {
});
describe('toNunjucksExt()', function() {
pit('should replace by block anchor', function() {
it('should replace by block anchor', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
return 'Hello';
});
@@ -97,7 +97,7 @@ describe('TemplateBlock', function() {
});
});
pit('must create a valid nunjucks extension', function() {
it('must create a valid nunjucks extension', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
return {
body: '<p>Hello, World!</p>',
@@ -120,7 +120,7 @@ describe('TemplateBlock', function() {
});
});
pit('must apply block arguments correctly', function() {
it('must apply block arguments correctly', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
return {
body: '<'+block.kwargs.tag+'>Hello, '+block.kwargs.name+'!</'+block.kwargs.tag+'>',
@@ -143,7 +143,7 @@ describe('TemplateBlock', function() {
});
});
pit('must accept an async function', function() {
it('must accept an async function', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
return Promise()
.then(function() {
@@ -169,7 +169,7 @@ describe('TemplateBlock', function() {
});
});
pit('must handle nested blocks', function() {
it('must handle nested blocks', function() {
var templateBlock = new TemplateBlock({
name: 'yoda',
blocks: Immutable.List(['start', 'end']),
+15 -1
View File
@@ -68,6 +68,20 @@ Config.prototype.getPluginDependencies = function() {
}
};
/**
Return a plugin dependency by its name
@param {String} name
@return {PluginDependency}
*/
Config.prototype.getPluginDependency = function(name) {
var plugins = this.getPluginDependencies();
return plugins.find(function(dep) {
return dep.getName() === name;
});
};
/**
Update the list of plugins dependencies
@@ -75,7 +89,7 @@ Config.prototype.getPluginDependencies = function() {
@return {Config}
*/
Config.prototype.setPluginDependencies = function(deps) {
var plugins = PluginDependency.listFromArray(deps);
var plugins = PluginDependency.listToArray(deps);
return this.setValue('plugins', plugins);
};
+23 -5
View File
@@ -29,6 +29,24 @@ PluginDependency.prototype.isEnabled = function() {
return this.get('enabled');
};
/**
Create a plugin with a name and a plugin
@param {String}
@return {Plugin|undefined}
*/
PluginDependency.create = function(name, version, enabled) {
if (is.undefined(enabled)) {
enabled = true;
}
return new PluginDependency({
name: name,
version: version || DEFAULT_VERSION,
enabled: Boolean(enabled)
});
};
/**
Create a plugin from a string
@@ -90,15 +108,15 @@ PluginDependency.listFromArray = function(arr) {
/**
Export plugin dependencies as an array
@param {List<PluginDependency>}
@param {List<PluginDependency>} list
@return {Array<String>}
*/
PluginDependency.listToArray = function(arr) {
return arr
PluginDependency.listToArray = function(list) {
return list
.map(function(dep) {
var result;
var result = '';
if (dep.isEnabled()) {
if (!dep.isEnabled()) {
result += '-';
}
@@ -0,0 +1,35 @@
var addPlugin = require('../addPlugin');
var Config = require('../../../models/config');
var Book = require('../../../models/book');
describe('addPlugin', function() {
var config = Config.createWithValues({
plugins: ['hello', 'world', '-disabled']
});
var book = Book().setConfig(config);
it('should have correct state of dependencies', function() {
var disabledDep = config.getPluginDependency('disabled');
expect(disabledDep).toBeDefined();
expect(disabledDep.getVersion()).toEqual('*');
expect(disabledDep.isEnabled()).toBeFalsy();
});
it('should add the plugin to the list', function() {
var newBook = addPlugin(book, 'test');
var newConfig = newBook.getConfig();
var testDep = newConfig.getPluginDependency('test');
expect(testDep).toBeDefined();
expect(testDep.getVersion()).toEqual('*');
expect(testDep.isEnabled()).toBeTruthy();
var disabledDep = newConfig.getPluginDependency('disabled');
expect(disabledDep).toBeDefined();
expect(disabledDep.getVersion()).toEqual('*');
expect(disabledDep.isEnabled()).toBeFalsy();
});
});
+1 -4
View File
@@ -11,10 +11,7 @@ function addPlugin(book, plugin, version) {
var config = book.getConfig();
var deps = config.getPluginDependencies();
var dep = PluginDependency({
name: plugin,
version: version
});
var dep = PluginDependency.create(plugin, version);
deps = deps.push(dep);
config = config.setPluginDependencies(deps);
+1 -1
View File
@@ -3,7 +3,7 @@ var EbookGenerator = require('../ebook');
describe('EbookGenerator', function() {
pit('should generate a SUMMARY.html', function() {
it('should generate a SUMMARY.html', function() {
return generateMock(EbookGenerator, {
'README.md': 'Hello World'
})
+2 -2
View File
@@ -3,7 +3,7 @@ var JSONGenerator = require('../json');
describe('JSONGenerator', function() {
pit('should generate a README.json', function() {
it('should generate a README.json', function() {
return generateMock(JSONGenerator, {
'README.md': 'Hello World'
})
@@ -12,7 +12,7 @@ describe('JSONGenerator', function() {
});
});
pit('should generate a json file for each articles', function() {
it('should generate a json file for each articles', function() {
return generateMock(JSONGenerator, {
'README.md': 'Hello World',
'SUMMARY.md': '# Summary\n\n* [Page](test/page.md)',
+10 -10
View File
@@ -3,7 +3,7 @@ var WebsiteGenerator = require('../website');
describe('WebsiteGenerator', function() {
pit('should generate an index.html', function() {
it('should generate an index.html', function() {
return generateMock(WebsiteGenerator, {
'README.md': 'Hello World'
})
@@ -12,7 +12,7 @@ describe('WebsiteGenerator', function() {
});
});
pit('should copy asset files', function() {
it('should copy asset files', function() {
return generateMock(WebsiteGenerator, {
'README.md': 'Hello World',
'myJsFile.js': 'var a = "test";',
@@ -27,7 +27,7 @@ describe('WebsiteGenerator', function() {
});
});
pit('should generate an index.html for AsciiDoc', function() {
it('should generate an index.html for AsciiDoc', function() {
return generateMock(WebsiteGenerator, {
'README.adoc': 'Hello World'
})
@@ -36,7 +36,7 @@ describe('WebsiteGenerator', function() {
});
});
pit('should generate an HTML file for each articles', function() {
it('should generate an HTML file for each articles', function() {
return generateMock(WebsiteGenerator, {
'README.md': 'Hello World',
'SUMMARY.md': '# Summary\n\n* [Page](test/page.md)',
@@ -50,7 +50,7 @@ describe('WebsiteGenerator', function() {
});
});
pit('should not generate file if entry file doesn\'t exist', function() {
it('should not generate file if entry file doesn\'t exist', function() {
return generateMock(WebsiteGenerator, {
'README.md': 'Hello World',
'SUMMARY.md': '# Summary\n\n* [Page 1](page.md)\n* [Page 2](test/page.md)',
@@ -60,12 +60,12 @@ describe('WebsiteGenerator', function() {
})
.then(function(folder) {
expect(folder).toHaveFile('index.html');
expect(folder).not.toHaveFile('page.html');
expect(folder).toNotHaveFile('page.html');
expect(folder).toHaveFile('test/page.html');
});
});
pit('should generate a multilingual book', function() {
it('should generate a multilingual book', function() {
return generateMock(WebsiteGenerator, {
'LANGS.md': '# Languages\n\n* [en](en)\n* [fr](fr)',
'en': {
@@ -81,12 +81,12 @@ describe('WebsiteGenerator', function() {
expect(folder).toHaveFile('fr/index.html');
// Should not copy languages as assets
expect(folder).not.toHaveFile('en/README.md');
expect(folder).not.toHaveFile('fr/README.md');
expect(folder).toNotHaveFile('en/README.md');
expect(folder).toNotHaveFile('fr/README.md');
// Should copy assets only once
expect(folder).toHaveFile('gitbook/style.css');
expect(folder).not.toHaveFile('en/gitbook/style.css');
expect(folder).toNotHaveFile('en/gitbook/style.css');
expect(folder).toHaveFile('index.html');
});
@@ -1,11 +1,8 @@
jest.autoMockOff();
var cheerio = require('cheerio');
var addHeadingId = require('../addHeadingId');
describe('addHeadingId', function() {
var addHeadingId = require('../addHeadingId');
pit('should add an ID if none', function() {
it('should add an ID if none', function() {
var $ = cheerio.load('<h1>Hello World</h1><h2>Cool !!</h2>');
return addHeadingId($)
@@ -15,7 +12,7 @@ describe('addHeadingId', function() {
});
});
pit('should not change existing IDs', function() {
it('should not change existing IDs', function() {
var $ = cheerio.load('<h1 id="awesome">Hello World</h1>');
return addHeadingId($)
@@ -1,12 +1,9 @@
jest.autoMockOff();
var Immutable = require('immutable');
var cheerio = require('cheerio');
var GlossaryEntry = require('../../../models/glossaryEntry');
var annotateText = require('../annotateText');
describe('annotateText', function() {
var annotateText = require('../annotateText');
var entries = Immutable.List([
GlossaryEntry({ name: 'Word' }),
GlossaryEntry({ name: 'Multiple Words' })
@@ -12,7 +12,7 @@ describe('fetchRemoteImages', function() {
dir = tmp.dirSync();
});
pit('should download image file', function() {
it('should download image file', function() {
var $ = cheerio.load('<img src="' + URL + '" />');
return fetchRemoteImages(dir.name, 'index.html', $)
@@ -24,7 +24,7 @@ describe('fetchRemoteImages', function() {
});
});
pit('should download image file and replace with relative path', function() {
it('should download image file and replace with relative path', function() {
var $ = cheerio.load('<img src="' + URL + '" />');
return fetchRemoteImages(dir.name, 'test/index.html', $)
@@ -1,11 +1,8 @@
jest.autoMockOff();
var cheerio = require('cheerio');
var Promise = require('../../../utils/promise');
var highlightCode = require('../highlightCode');
describe('highlightCode', function() {
var highlightCode = require('../highlightCode');
function doHighlight(lang, code) {
return {
text: '' + (lang || '') + '$' + code
@@ -19,7 +16,7 @@ describe('highlightCode', function() {
});
}
pit('should call it for normal code element', function() {
it('should call it for normal code element', function() {
var $ = cheerio.load('<p>This is a <code>test</code></p>');
return highlightCode(doHighlight, $)
@@ -29,7 +26,7 @@ describe('highlightCode', function() {
});
});
pit('should call it for markdown code block', function() {
it('should call it for markdown code block', function() {
var $ = cheerio.load('<pre><code class="lang-js">test</code></pre>');
return highlightCode(doHighlight, $)
@@ -39,7 +36,7 @@ describe('highlightCode', function() {
});
});
pit('should call it for asciidoc code block', function() {
it('should call it for asciidoc code block', function() {
var $ = cheerio.load('<pre><code class="language-python">test</code></pre>');
return highlightCode(doHighlight, $)
@@ -49,7 +46,7 @@ describe('highlightCode', function() {
});
});
pit('should accept async highlighter', function() {
it('should accept async highlighter', function() {
var $ = cheerio.load('<pre><code class="language-python">test</code></pre>');
return highlightCode(doHighlightAsync, $)
+1 -1
View File
@@ -9,7 +9,7 @@ describe('inlinePng', function() {
dir = tmp.dirSync();
});
pit('should write an inline PNG using data URI as a file', function() {
it('should write an inline PNG using data URI as a file', function() {
var $ = cheerio.load('<img alt="GitBook Logo 20x20" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUEAYAAADdGcFOAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpMwidZAAAF+klEQVRIDY3Wf5CVVR3H8c9z791fyI9dQwdQ4TTI7wEWnQZZAa/mJE4Z0OaKUuN1KoaykZxUGGHay+iIVFMoEYrUPhDCKEKW2ChT8dA0RCSxWi6EW3sYYpcfxq5C+4O9957O+7m7O/qHQ9/XzH1+nHuec57z8wkWTsKw0y6N/LxXN6KzTnEUHi8eP/l3YStSU/MdsYvBbGh8six2YXcbcgc++QkfTQkWz/81KtqDA0hlUoWnsX+5uxe5X365BB9my2bjrHNHccLk16BpS9CExjcmXMDbD6wehdyEjxbjz1uK1zn9qga6dcfnMLXeXY/qjuQqTF4W1MKke8ZgeNhjMCxMPIWSd4OF78C55CFI/1kF6WwXpMqjkAZ/CKniNDrCsmU4lE1YbPlgR2x7R39FF23D4mq3A1+Z35PGTNs1E1XhxcGQOh6HNPwXkK56BVJhOaRg/pvoHXNxHFw410B25EYE2RMvI0i/twFJvXcrFObykEa+DmnQGLwYqR0l2a6JqItaj8C/4E2QxtZCofkC8tF1t8HZc/fAZaLnIF2xEsoEtW1w7vBSSFtfhDTnCki9cSi81Ain1uko2Ld+Dmf2rkUq0/5t+PYbFtPQdkjzNiAXTWtDEF49FgkzJInAVPwNyhzcDOmrdZCm/Rn+ebWtcPs+/U24hmg2XL0rRkPPELh9R8fDtXR2oC/VuZbGaci79Ajkb6lZgfyYtyzy/X9s6T/pO/ZfN/RdNxxIwTWM2wbX8KVmuIaEqmKm6zEondwGpd0SyOy5DrJ//TFkX9kMhd3XQHbEVCSsm4OECV5HIv2p15CwfWPSntoHRbv2Q1HzSvSlSqZwATIuBxk/zZBOBbdB+u9hSKU3Q7pwAjInZkFm6U8hu7MSMqe/Dqn8fUj5GVCmpxK+4N/F1LMa0p5eSOPqIPP7NGSunAI/+R6GnzQzIBt8A1LC/QZ+6HwLst1rITv0n5CtXgSZ78yFTNkR+FdeDZneJkip3fAtsQ5Scilkek7CH9dAmjIWvkK7IXXOh6/IzZDNPQdZXR1TQmdjKv0ZfEu0YKDpNflpyG5aDtnRv8VAuu3dBV+huyBbvgdS97tQNLQc0mfugKy5Cb4BipPIXvsUpK5N8Mvao/Bd3QDZRH9Rrtj3Cl6FHwPFMLmNkKrj8BnHoT+XX6f2wl+XxFS4Ab7C72Dgf7bi+5DpTkNm8kQMpCs/BzIlz8LfPxnzLdh3EjwMX4GX4Ju4GNb9A1L7k/D3J8b6kv2LFCtmCmcgUzoJsr2z4MfwFsh87xikZefg188fYaAhpPUxm3ge/vFnYkoED0HqeQiyJYcwkNGWnoNv6s9C1p1Bf/389VYoCjohW7UfMms3wXdpBv7+FEiPLIHs4DIMNERUNhbSpY3wk6QOsqlCDVx2xCrInMpBmfNPQOnzKxBkkrugdOl9GKigSZZCUWIm/GqwDtLUI5D+WAOlb9wKP0YvQLbjZSjsaYaL/n0/FA3fDtnCGihK5UYjCK+ZDr+TDIKLdm2Fs1UOzo76F5wO74XSZj0S6d7RCMLkCshcXALZxaWQRjXDZQ62oRAdCeG/Ju5HELX2QFH3C0hkRy6GovyfwF58AoVbguOxyB2H7/I34Gf11yANnQSp7Vr4MbQH0vg7kbNNp5AM3UrIVDchnz56B1Jm573wW9gZSFVPwO/hefg5FsIvN09CchtQCIOFw/F5U8ii3CZn4cqo7C8YlXEPYkx9cacZl00+iwnprrtwVdj1Q/gXmAs/pu6LZc9XQOGgSvh19n2cDZN341g2EcfxTEGwH/RewqlMsUfbbWIGLjUG+j/j9nokD1beiOvLS5dhjr30Gu6ZnivgdtM/6VJvY1+6pBHbH+h9CX84vfMxNJtisYVFlys+WNCIZJNmIsjohlhNSQC3f8R55H+y/hjkN8GPR9ndCLJxT4/3n0Px51ay8XQnNrYfDJHf//Fc0oMrEZSeeQGJ7+Z+gKCgLbHNWgXnB9FlYt5JaN38JIINC95EakjtAqQeuUx21c5B6tEFf0fSfbEFQf28Z6D6y+X/H0jf40QQJhYwAAAAAElFTkSuQmCC"/>');
return inlinePng(dir.name, 'index.html', $)
@@ -1,11 +1,8 @@
jest.autoMockOff();
var path = require('path');
var cheerio = require('cheerio');
var resolveLinks = require('../resolveLinks');
describe('resolveLinks', function() {
var resolveLinks = require('../resolveLinks');
function resolveFileBasic(href) {
return href;
}
@@ -21,7 +18,7 @@ describe('resolveLinks', function() {
describe('Absolute path', function() {
var TEST = '<p>This is a <a href="/test/cool.md"></a></p>';
pit('should resolve path starting by "/" in root directory', function() {
it('should resolve path starting by "/" in root directory', function() {
var $ = cheerio.load(TEST);
return resolveLinks('hello.md', resolveFileBasic, $)
@@ -31,7 +28,7 @@ describe('resolveLinks', function() {
});
});
pit('should resolve path starting by "/" in child directory', function() {
it('should resolve path starting by "/" in child directory', function() {
var $ = cheerio.load(TEST);
return resolveLinks('afolder/hello.md', resolveFileBasic, $)
@@ -45,7 +42,7 @@ describe('resolveLinks', function() {
describe('Custom Resolver', function() {
var TEST = '<p>This is a <a href="/test/cool.md"></a> <a href="afile.png"></a></p>';
pit('should resolve path correctly for absolute path', function() {
it('should resolve path correctly for absolute path', function() {
var $ = cheerio.load(TEST);
return resolveLinks('hello.md', resolveFileCustom, $)
@@ -55,7 +52,7 @@ describe('resolveLinks', function() {
});
});
pit('should resolve path correctly for absolute path (2)', function() {
it('should resolve path correctly for absolute path (2)', function() {
var $ = cheerio.load(TEST);
return resolveLinks('afodler/hello.md', resolveFileCustom, $)
+1 -1
View File
@@ -9,7 +9,7 @@ describe('svgToImg', function() {
dir = tmp.dirSync();
});
pit('should write svg as a file', function() {
it('should write svg as a file', function() {
var $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
return svgToImg(dir.name, 'index.html', $)
+4 -3
View File
@@ -2,16 +2,17 @@ var cheerio = require('cheerio');
var tmp = require('tmp');
var path = require('path');
var svgToImg = require('../svgToImg');
var svgToPng = require('../svgToPng');
describe('svgToPng', function() {
var dir;
var svgToImg = require('../svgToImg');
var svgToPng = require('../svgToPng');
beforeEach(function() {
dir = tmp.dirSync();
});
pit('should write svg as png file', function() {
it('should write svg as png file', function() {
var $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
var fileName = 'index.html';
+1 -1
View File
@@ -6,7 +6,7 @@ var listAssets = require('../listAssets');
var parseGlossary = require('../parseGlossary');
describe('listAssets', function() {
pit('should not list glossary as asset', function() {
it('should not list glossary as asset', function() {
var fs = createMockFS({
'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello',
'assetFile.js': '',
+2 -2
View File
@@ -4,7 +4,7 @@ var createMockFS = require('../../fs/mock');
describe('parseBook', function() {
var parseBook = require('../parseBook');
pit('should parse multilingual book', function() {
it('should parse multilingual book', function() {
var fs = createMockFS({
'LANGS.md': '# Languages\n\n* [en](en)\n* [fr](fr)',
'en': {
@@ -27,7 +27,7 @@ describe('parseBook', function() {
});
});
pit('should parse book in a directory', function() {
it('should parse book in a directory', function() {
var fs = createMockFS({
'book.json': JSON.stringify({
root: './test'
+2 -2
View File
@@ -4,7 +4,7 @@ var createMockFS = require('../../fs/mock');
describe('parseGlossary', function() {
var parseGlossary = require('../parseGlossary');
pit('should parse glossary if exists', function() {
it('should parse glossary if exists', function() {
var fs = createMockFS({
'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello'
});
@@ -21,7 +21,7 @@ describe('parseGlossary', function() {
});
});
pit('should not fail if doesn\'t exist', function() {
it('should not fail if doesn\'t exist', function() {
var fs = createMockFS({});
var book = Book.createForFS(fs);
+3 -3
View File
@@ -17,21 +17,21 @@ describe('parseIgnore', function() {
return parseIgnore(book);
}
pit('should load rules from .ignore', function() {
it('should load rules from .ignore', function() {
return getBook()
.then(function(book) {
expect(book.isFileIgnored('test-1.js')).toBeTruthy();
});
});
pit('should load rules from .gitignore', function() {
it('should load rules from .gitignore', function() {
return getBook()
.then(function(book) {
expect(book.isFileIgnored('test-2.js')).toBeTruthy();
});
});
pit('should load rules from .bookignore', function() {
it('should load rules from .bookignore', function() {
return getBook()
.then(function(book) {
expect(book.isFileIgnored('test-3.js')).toBeFalsy();
+2 -2
View File
@@ -5,7 +5,7 @@ var createMockFS = require('../../fs/mock');
describe('parseReadme', function() {
var parseReadme = require('../parseReadme');
pit('should parse summary if exists', function() {
it('should parse summary if exists', function() {
var fs = createMockFS({
'README.md': '# Hello\n\nAnd here is the description.'
});
@@ -22,7 +22,7 @@ describe('parseReadme', function() {
});
});
pit('should fail if doesn\'t exist', function() {
it('should fail if doesn\'t exist', function() {
var fs = createMockFS({});
var book = Book.createForFS(fs);
+2 -2
View File
@@ -4,7 +4,7 @@ var createMockFS = require('../../fs/mock');
describe('parseSummary', function() {
var parseSummary = require('../parseSummary');
pit('should parse summary if exists', function() {
it('should parse summary if exists', function() {
var fs = createMockFS({
'SUMMARY.md': '# Summary\n\n* [Hello](hello.md)'
});
@@ -19,7 +19,7 @@ describe('parseSummary', function() {
});
});
pit('should not fail if doesn\'t exist', function() {
it('should not fail if doesn\'t exist', function() {
var fs = createMockFS({});
var book = Book.createForFS(fs);
+1 -1
View File
@@ -4,7 +4,7 @@ var Immutable = require('immutable');
describe('findInstalled', function() {
var findInstalled = require('../findInstalled');
pit('must list default plugins for gitbook directory', function() {
it('must list default plugins for gitbook directory', function() {
// Read gitbook-plugins from package.json
var pkg = require(path.resolve(__dirname, '../../../package.json'));
var gitbookPlugins = Immutable.Seq(pkg.dependencies)
+2 -7
View File
@@ -1,13 +1,9 @@
jest.autoMockOff();
var Promise = require('../../utils/promise');
var Plugin = require('../../models/plugin');
var validatePlugin = require('../validatePlugin');
describe('validatePlugin', function() {
var validatePlugin = require('../validatePlugin');
pit('must not validate a not loaded plugin', function() {
it('must not validate a not loaded plugin', function() {
var plugin = Plugin.createFromString('test');
return validatePlugin(plugin)
@@ -17,5 +13,4 @@ describe('validatePlugin', function() {
return Promise();
});
});
});
+3 -3
View File
@@ -9,21 +9,21 @@ describe('ConrefsLoader', function() {
});
describe('Git', function() {
pit('should include content from git', function() {
it('should include content from git', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('Hello from git');
});
});
pit('should handle deep inclusion (1)', function() {
it('should handle deep inclusion (1)', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('First Hello. Hello from git');
});
});
pit('should handle deep inclusion (2)', function() {
it('should handle deep inclusion (2)', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
.then(function(out) {
expect(out.getContent()).toBe('First Hello. Hello from git');
+3 -3
View File
@@ -15,8 +15,8 @@ describe('Git', function() {
expect(Git.isUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1')).toBeTruthy();
// Non valid
expect(Git.isUrl('https://github.com/Hello/world.git')).not.toBeTruthy();
expect(Git.isUrl('README.md')).not.toBeTruthy();
expect(Git.isUrl('https://github.com/Hello/world.git')).toBeFalsy();
expect(Git.isUrl('README.md')).toBeFalsy();
});
it('should parse HTTPS urls', function() {
@@ -45,7 +45,7 @@ describe('Git', function() {
});
describe('Cloning and resolving', function() {
pit('should clone an HTTPS url', function() {
it('should clone an HTTPS url', function() {
var git = new Git(path.join(os.tmpdir(), 'test-git-'+Date.now()));
return git.resolve('git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md')
.then(function(filename) {
+1 -3
View File
@@ -1,8 +1,6 @@
jest.autoMockOff();
var LocationUtils = require('../location');
describe('LocationUtils', function() {
var LocationUtils = require('../location');
it('should correctly test external location', function() {
expect(LocationUtils.isExternal('http://google.fr')).toBe(true);
expect(LocationUtils.isExternal('https://google.fr')).toBe(true);
+5 -11
View File
@@ -62,11 +62,12 @@
},
"devDependencies": {
"eslint": "2.9.0",
"jest-cli": "12.0.2"
"expect": "^1.20.1",
"mocha": "^2.4.5"
},
"scripts": {
"test": "node_modules/.bin/jest --bail",
"lint": "eslint ."
"lint": "eslint .",
"test": "./node_modules/.bin/mocha ./testing/setup.js './lib/**/*/__tests__/*.js' --bail --reporter=list --timeout=5000"
},
"repository": {
"type": "git",
@@ -94,12 +95,5 @@
"name": "Samy Pessé",
"email": "samy@gitbook.com"
}
],
"jest": {
"automock": false,
"setupTestFrameworkScriptFile": "<rootDir>/jest/customMatchers.js",
"globals": {
"__DEV__": true
}
}
]
}
+49
View File
@@ -0,0 +1,49 @@
var is = require('is');
var path = require('path');
var fs = require('fs');
var expect = require('expect');
expect.extend({
/**
Check that a file is created in a directory:
expect('myFolder').toHaveFile('hello.md');
*/
toHaveFile: function(fileName) {
var filePath = path.join(this.actual, fileName);
var exists = fs.existsSync(filePath);
expect.assert(
exists,
'expected %s to have file %s',
this.actual,
fileName
);
return this;
},
toNotHaveFile: function(fileName) {
var filePath = path.join(this.actual, fileName);
var exists = fs.existsSync(filePath);
expect.assert(
!exists,
'expected %s to not have file %s',
this.actual,
fileName
);
return this;
},
/**
Check that a value is defined (not null nor undefined)
*/
toBeDefined: function() {
expect.assert(
!(is.undefined(this.actual) || is.null(this.actual)),
'expected to be defined'
);
return this;
}
});
global.expect = expect;