diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-11 13:02:20 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-11 13:02:24 +0200 |
commit | ef589a6b133ac67a7904f8bb2cbec42c96dec914 (patch) | |
tree | d505c567cd80b0681bbf5f7b46b2a25ed591e28a /lib/models | |
parent | d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (diff) | |
download | gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.zip gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.gz gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.bz2 |
Switch tests to mocha while keeping jest structure
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/__tests__/config.js | 5 | ||||
-rw-r--r-- | lib/models/__tests__/glossary.js | 10 | ||||
-rw-r--r-- | lib/models/__tests__/glossaryEntry.js | 4 | ||||
-rw-r--r-- | lib/models/__tests__/pluginDependency.js | 19 | ||||
-rw-r--r-- | lib/models/__tests__/summary.js | 2 | ||||
-rw-r--r-- | lib/models/__tests__/templateBlock.js | 14 | ||||
-rw-r--r-- | lib/models/config.js | 16 | ||||
-rw-r--r-- | lib/models/pluginDependency.js | 28 |
8 files changed, 69 insertions, 29 deletions
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 += '-'; } |