summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-11 13:02:20 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-11 13:02:24 +0200
commitef589a6b133ac67a7904f8bb2cbec42c96dec914 (patch)
treed505c567cd80b0681bbf5f7b46b2a25ed591e28a
parentd5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (diff)
downloadgitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.zip
gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.gz
gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.bz2
Switch tests to mocha while keeping jest structure
-rw-r--r--jest/customMatchers.js25
-rw-r--r--lib/__tests__/init.js2
-rw-r--r--lib/fs/__tests__/mock.js19
-rw-r--r--lib/models/__tests__/config.js5
-rw-r--r--lib/models/__tests__/glossary.js10
-rw-r--r--lib/models/__tests__/glossaryEntry.js4
-rw-r--r--lib/models/__tests__/pluginDependency.js19
-rw-r--r--lib/models/__tests__/summary.js2
-rw-r--r--lib/models/__tests__/templateBlock.js14
-rw-r--r--lib/models/config.js16
-rw-r--r--lib/models/pluginDependency.js28
-rw-r--r--lib/modifiers/config/__tests__/addPlugin.js35
-rw-r--r--lib/modifiers/config/addPlugin.js5
-rw-r--r--lib/output/__tests__/ebook.js2
-rw-r--r--lib/output/__tests__/json.js4
-rw-r--r--lib/output/__tests__/website.js20
-rw-r--r--lib/output/modifiers/__tests__/addHeadingId.js9
-rw-r--r--lib/output/modifiers/__tests__/annotateText.js5
-rw-r--r--lib/output/modifiers/__tests__/fetchRemoteImages.js4
-rw-r--r--lib/output/modifiers/__tests__/highlightCode.js13
-rw-r--r--lib/output/modifiers/__tests__/inlinePng.js2
-rw-r--r--lib/output/modifiers/__tests__/resolveLinks.js13
-rw-r--r--lib/output/modifiers/__tests__/svgToImg.js2
-rw-r--r--lib/output/modifiers/__tests__/svgToPng.js7
-rw-r--r--lib/parse/__tests__/listAssets.js2
-rw-r--r--lib/parse/__tests__/parseBook.js4
-rw-r--r--lib/parse/__tests__/parseGlossary.js4
-rw-r--r--lib/parse/__tests__/parseIgnore.js6
-rw-r--r--lib/parse/__tests__/parseReadme.js4
-rw-r--r--lib/parse/__tests__/parseSummary.js4
-rw-r--r--lib/plugins/__tests__/findInstalled.js2
-rw-r--r--lib/plugins/__tests__/validatePlugin.js9
-rw-r--r--lib/templating/__tests__/conrefsLoader.js6
-rw-r--r--lib/utils/__tests__/git.js6
-rw-r--r--lib/utils/__tests__/location.js4
-rw-r--r--package.json16
-rw-r--r--testing/setup.js49
37 files changed, 226 insertions, 155 deletions
diff --git a/jest/customMatchers.js b/jest/customMatchers.js
deleted file mode 100644
index 4dd4f68..0000000
--- a/jest/customMatchers.js
+++ /dev/null
@@ -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);
-}); \ No newline at end of file
diff --git a/lib/__tests__/init.js b/lib/__tests__/init.js
index 5665cf1..66188a3 100644
--- a/lib/__tests__/init.js
+++ b/lib/__tests__/init.js
@@ -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)
diff --git a/lib/fs/__tests__/mock.js b/lib/fs/__tests__/mock.js
index 7842011..04bd46a 100644
--- a/lib/fs/__tests__/mock.js
+++ b/lib/fs/__tests__/mock.js
@@ -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);
diff --git a/lib/models/__tests__/config.js b/lib/models/__tests__/config.js
index 8445cef..ff04ffd 100644
--- a/lib/models/__tests__/config.js
+++ b/lib/models/__tests__/config.js
@@ -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,
diff --git a/lib/models/__tests__/glossary.js b/lib/models/__tests__/glossary.js
index 2ce224c..5bf64dc 100644
--- a/lib/models/__tests__/glossary.js
+++ b/lib/models/__tests__/glossary.js
@@ -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');
diff --git a/lib/models/__tests__/glossaryEntry.js b/lib/models/__tests__/glossaryEntry.js
index 9eabc68..833115d 100644
--- a/lib/models/__tests__/glossaryEntry.js
+++ b/lib/models/__tests__/glossaryEntry.js
@@ -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({
diff --git a/lib/models/__tests__/pluginDependency.js b/lib/models/__tests__/pluginDependency.js
index 8aa55fb..0b105e9 100644
--- a/lib/models/__tests__/pluginDependency.js
+++ b/lib/models/__tests__/pluginDependency.js
@@ -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'
+ ]);
+ });
});
diff --git a/lib/models/__tests__/summary.js b/lib/models/__tests__/summary.js
index f73e49b..29c9330 100644
--- a/lib/models/__tests__/summary.js
+++ b/lib/models/__tests__/summary.js
@@ -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');
diff --git a/lib/models/__tests__/templateBlock.js b/lib/models/__tests__/templateBlock.js
index fdd0210..e5f7666 100644
--- a/lib/models/__tests__/templateBlock.js
+++ b/lib/models/__tests__/templateBlock.js
@@ -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']),
diff --git a/lib/models/config.js b/lib/models/config.js
index 3310a93..070fe92 100644
--- a/lib/models/config.js
+++ b/lib/models/config.js
@@ -69,13 +69,27 @@ 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
@param {List<PluginDependency>}
@return {Config}
*/
Config.prototype.setPluginDependencies = function(deps) {
- var plugins = PluginDependency.listFromArray(deps);
+ var plugins = PluginDependency.listToArray(deps);
return this.setValue('plugins', plugins);
};
diff --git a/lib/models/pluginDependency.js b/lib/models/pluginDependency.js
index bb8e4b4..3502468 100644
--- a/lib/models/pluginDependency.js
+++ b/lib/models/pluginDependency.js
@@ -30,6 +30,24 @@ PluginDependency.prototype.isEnabled = function() {
};
/**
+ 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
@param {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 += '-';
}
diff --git a/lib/modifiers/config/__tests__/addPlugin.js b/lib/modifiers/config/__tests__/addPlugin.js
new file mode 100644
index 0000000..319a980
--- /dev/null
+++ b/lib/modifiers/config/__tests__/addPlugin.js
@@ -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();
+ });
+});
+
+
diff --git a/lib/modifiers/config/addPlugin.js b/lib/modifiers/config/addPlugin.js
index 2a04a03..b4fd227 100644
--- a/lib/modifiers/config/addPlugin.js
+++ b/lib/modifiers/config/addPlugin.js
@@ -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);
diff --git a/lib/output/__tests__/ebook.js b/lib/output/__tests__/ebook.js
index dabf360..bcac990 100644
--- a/lib/output/__tests__/ebook.js
+++ b/lib/output/__tests__/ebook.js
@@ -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'
})
diff --git a/lib/output/__tests__/json.js b/lib/output/__tests__/json.js
index 94a0362..46ab42f 100644
--- a/lib/output/__tests__/json.js
+++ b/lib/output/__tests__/json.js
@@ -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)',
diff --git a/lib/output/__tests__/website.js b/lib/output/__tests__/website.js
index d9fe123..554c56c 100644
--- a/lib/output/__tests__/website.js
+++ b/lib/output/__tests__/website.js
@@ -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');
});
diff --git a/lib/output/modifiers/__tests__/addHeadingId.js b/lib/output/modifiers/__tests__/addHeadingId.js
index 7277440..a3b1d81 100644
--- a/lib/output/modifiers/__tests__/addHeadingId.js
+++ b/lib/output/modifiers/__tests__/addHeadingId.js
@@ -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($)
diff --git a/lib/output/modifiers/__tests__/annotateText.js b/lib/output/modifiers/__tests__/annotateText.js
index 15d4c30..40b1e6c 100644
--- a/lib/output/modifiers/__tests__/annotateText.js
+++ b/lib/output/modifiers/__tests__/annotateText.js
@@ -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' })
diff --git a/lib/output/modifiers/__tests__/fetchRemoteImages.js b/lib/output/modifiers/__tests__/fetchRemoteImages.js
index f5610a2..bc1704d 100644
--- a/lib/output/modifiers/__tests__/fetchRemoteImages.js
+++ b/lib/output/modifiers/__tests__/fetchRemoteImages.js
@@ -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', $)
diff --git a/lib/output/modifiers/__tests__/highlightCode.js b/lib/output/modifiers/__tests__/highlightCode.js
index bd7d422..75d9902 100644
--- a/lib/output/modifiers/__tests__/highlightCode.js
+++ b/lib/output/modifiers/__tests__/highlightCode.js
@@ -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, $)
diff --git a/lib/output/modifiers/__tests__/inlinePng.js b/lib/output/modifiers/__tests__/inlinePng.js
index fb094f7..0073cff 100644
--- a/lib/output/modifiers/__tests__/inlinePng.js
+++ b/lib/output/modifiers/__tests__/inlinePng.js
@@ -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/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjph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LJxT4/3n0Px51ay8XQnNrYfDJHf//Fc0oMrEZSeeQGJ7+Z+gKCgLbHNWgXnB9FlYt5JaN38JIINC95EakjtAqQeuUx21c5B6tEFf0fSfbEFQf28Z6D6y+X/H0jf40QQJhYwAAAAAElFTkSuQmCC"/>');
return inlinePng(dir.name, 'index.html', $)
diff --git a/lib/output/modifiers/__tests__/resolveLinks.js b/lib/output/modifiers/__tests__/resolveLinks.js
index 3d50d80..9b7621b 100644
--- a/lib/output/modifiers/__tests__/resolveLinks.js
+++ b/lib/output/modifiers/__tests__/resolveLinks.js
@@ -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, $)
diff --git a/lib/output/modifiers/__tests__/svgToImg.js b/lib/output/modifiers/__tests__/svgToImg.js
index 793395e..5fe9796 100644
--- a/lib/output/modifiers/__tests__/svgToImg.js
+++ b/lib/output/modifiers/__tests__/svgToImg.js
@@ -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', $)
diff --git a/lib/output/modifiers/__tests__/svgToPng.js b/lib/output/modifiers/__tests__/svgToPng.js
index 163d72e..dbb3502 100644
--- a/lib/output/modifiers/__tests__/svgToPng.js
+++ b/lib/output/modifiers/__tests__/svgToPng.js
@@ -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';
diff --git a/lib/parse/__tests__/listAssets.js b/lib/parse/__tests__/listAssets.js
index 2f66fd1..4c5b0a0 100644
--- a/lib/parse/__tests__/listAssets.js
+++ b/lib/parse/__tests__/listAssets.js
@@ -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': '',
diff --git a/lib/parse/__tests__/parseBook.js b/lib/parse/__tests__/parseBook.js
index 25d1802..912d32d 100644
--- a/lib/parse/__tests__/parseBook.js
+++ b/lib/parse/__tests__/parseBook.js
@@ -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'
diff --git a/lib/parse/__tests__/parseGlossary.js b/lib/parse/__tests__/parseGlossary.js
index 53805fe..9069af6 100644
--- a/lib/parse/__tests__/parseGlossary.js
+++ b/lib/parse/__tests__/parseGlossary.js
@@ -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);
diff --git a/lib/parse/__tests__/parseIgnore.js b/lib/parse/__tests__/parseIgnore.js
index bee4236..54e7dae 100644
--- a/lib/parse/__tests__/parseIgnore.js
+++ b/lib/parse/__tests__/parseIgnore.js
@@ -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();
diff --git a/lib/parse/__tests__/parseReadme.js b/lib/parse/__tests__/parseReadme.js
index 1b1567b..4270ea3 100644
--- a/lib/parse/__tests__/parseReadme.js
+++ b/lib/parse/__tests__/parseReadme.js
@@ -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);
diff --git a/lib/parse/__tests__/parseSummary.js b/lib/parse/__tests__/parseSummary.js
index 4b4650d..55a445e 100644
--- a/lib/parse/__tests__/parseSummary.js
+++ b/lib/parse/__tests__/parseSummary.js
@@ -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);
diff --git a/lib/plugins/__tests__/findInstalled.js b/lib/plugins/__tests__/findInstalled.js
index 85e133f..9377190 100644
--- a/lib/plugins/__tests__/findInstalled.js
+++ b/lib/plugins/__tests__/findInstalled.js
@@ -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)
diff --git a/lib/plugins/__tests__/validatePlugin.js b/lib/plugins/__tests__/validatePlugin.js
index 3d50839..635423c 100644
--- a/lib/plugins/__tests__/validatePlugin.js
+++ b/lib/plugins/__tests__/validatePlugin.js
@@ -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();
});
});
-
});
diff --git a/lib/templating/__tests__/conrefsLoader.js b/lib/templating/__tests__/conrefsLoader.js
index ff484b7..d430a4f 100644
--- a/lib/templating/__tests__/conrefsLoader.js
+++ b/lib/templating/__tests__/conrefsLoader.js
@@ -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');
diff --git a/lib/utils/__tests__/git.js b/lib/utils/__tests__/git.js
index 90555b6..abc1ea1 100644
--- a/lib/utils/__tests__/git.js
+++ b/lib/utils/__tests__/git.js
@@ -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) {
diff --git a/lib/utils/__tests__/location.js b/lib/utils/__tests__/location.js
index 1d75751..2d01714 100644
--- a/lib/utils/__tests__/location.js
+++ b/lib/utils/__tests__/location.js
@@ -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);
diff --git a/package.json b/package.json
index 0658afe..124558c 100644
--- a/package.json
+++ b/package.json
@@ -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
- }
- }
+ ]
}
diff --git a/testing/setup.js b/testing/setup.js
new file mode 100644
index 0000000..b91a299
--- /dev/null
+++ b/testing/setup.js
@@ -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;