Skip to content

Commit b9f55ce

Browse files
committed
Fix tests
1 parent eda3262 commit b9f55ce

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

bin/gitbook.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ var parsedArgv = require('optimist').argv;
88
var color = require('bash-color');
99

1010
var pkg = require('../package.json');
11-
var config = require('../lib/config');
1211
var manager = require('../lib');
13-
var registry = require('../lib/registry');
1412
var commands = require('../lib/commands');
1513

1614
// Which book is concerned?
@@ -30,7 +28,7 @@ function runPromise(p) {
3028

3129

3230
// Init gitbook-cli
33-
config.init();
31+
manager.init();
3432

3533
program
3634
.version(pkg.version)

lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Q = require('q');
22
var _ = require('lodash');
33

4+
var config = require('./config');
45
var local = require('./local');
56
var registry = require('./registry');
67

@@ -82,10 +83,12 @@ function updateVersion(tag) {
8283
}
8384

8485
module.exports = {
86+
init: config.init,
87+
setRoot: config.setRoot,
88+
8589
load: local.load,
8690
ensure: ensureVersion,
8791
ensureAndLoad: ensureAndLoad,
88-
current: local.current,
8992
uninstall: local.remove,
9093
link: local.link,
9194
versions: local.versions,

lib/local.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ function loadVersion(version) {
113113

114114
// Link a folder to a tag
115115
function linkVersion(name, folder) {
116-
if (!name) return Q.reject(new Error('Need a version to represent this folder'));
117-
if (!folder) return Q.reject(new Error('Need a folder'));
118-
var outputFolder = path.resolve(config.VERSIONS_ROOT, version);
116+
if (!name) return Q.reject(new Error('Require a name to represent this GitBook version'));
117+
if (!folder) return Q.reject(new Error('Require a folder'));
118+
var outputFolder = versionRoot(name);
119119

120120
return Q.nfcall(fs.symlink.bind(fs), folder, outputFolder);
121121
}

test/_helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var path = require('path');
22
var fs = require('fs-extra');
3-
var config = require('../lib/config');
3+
var manager = require('../lib');
44

55
// Use tmp folder for testing
66
before(function() {
77
var gitbookFolder = path.resolve(__dirname, '../.tmp');
88
fs.removeSync(gitbookFolder);
9-
config.setRoot(gitbookFolder);
10-
config.init();
9+
manager.setRoot(gitbookFolder);
10+
manager.init();
1111
});

test/tags.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ var should = require('should');
22
var tags = require('../lib/tags');
33

44
describe('Tags', function() {
5-
6-
describe('tags.isValid()', function() {
5+
describe('.isValid()', function() {
76
it('should return true for version >= 2.0.0', function() {
87
tags.isValid('2.0.0').should.be.ok()
98
});
@@ -13,4 +12,9 @@ describe('Tags', function() {
1312
});
1413
});
1514

15+
describe('.satisfies()', function() {
16+
it('should return true for tag and *', function() {
17+
tags.satisfies('pre', '*').should.be.ok()
18+
});
19+
});
1620
});

test/versions.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
var path = require('path');
22
var should = require('should');
33

4-
var versions = require('../lib/versions');
4+
var manager = require('../lib');
55

66
describe('Versions', function() {
77
this.timeout(50000);
88

9-
describe('versions.available()', function() {
9+
describe('.available()', function() {
1010
var result;
1111

1212
before(function() {
13-
return versions.available()
13+
return manager.available()
1414
.then(function(versions) {
1515
result = versions;
1616
});
@@ -27,11 +27,11 @@ describe('Versions', function() {
2727
});
2828
});
2929

30-
describe('versions.install()', function() {
30+
describe('.install()', function() {
3131
var result;
3232

3333
before(function() {
34-
return versions.install('2.0.0')
34+
return manager.install('2.0.0')
3535
.then(function(version) {
3636
result = version;
3737
});
@@ -43,57 +43,58 @@ describe('Versions', function() {
4343
});
4444
});
4545

46-
describe('versions.current()', function() {
46+
describe('.ensure()', function() {
4747
it('should correctly return installed version', function() {
48-
return versions.current()
48+
return manager.ensure(__dirname)
4949
.then(function(v) {
5050
v.should.have.properties('version', 'path');
5151
v.version.should.equal('2.0.0');
5252
});
5353
});
5454
});
5555

56-
describe('versions.list()', function() {
56+
describe('.list()', function() {
5757
var result;
5858

5959
before(function() {
60-
result = versions.list();
60+
result = manager.versions();
6161
});
6262

6363
it('should correctly return the installed version', function() {
6464
result.should.be.an.Array();
6565
result.should.have.lengthOf(1);
66-
result[0].should.have.properties('version', 'path');
66+
result[0].should.have.properties('name', 'tag', 'version', 'path');
6767
result[0].version.should.equal('2.0.0');
6868
});
6969
});
7070

71-
describe('versions.link()', function() {
71+
describe('.link()', function() {
7272
var localGitbook = path.resolve(__dirname, '../node_modules/gitbook');
7373

7474
before(function() {
75-
return versions.link('latest', localGitbook);
75+
return manager.link('latest', localGitbook);
7676
});
7777

7878
it('should correctly list latest version', function() {
79-
var result = versions.list();
79+
var result = manager.versions();
8080
result.should.have.lengthOf(2);
8181
result[0].should.have.properties('version', 'path');
82-
result[0].tag.should.equal('latest');
82+
result[0].tag.should.equal('beta');
83+
result[0].name.should.equal('latest');
8384
result[0].link.should.equal(localGitbook);
8485
});
8586

8687
it('should correctly return latest version as default one', function() {
87-
return versions.current()
88+
return manager.get(__dirname)
8889
.then(function(version) {
89-
version.tag.should.equal('latest');
90+
version.name.should.equal('latest');
9091
});
9192
});
9293
});
9394

94-
describe('versions.get()', function() {
95+
describe('.load()', function() {
9596
it('should correctly return gitbook instance', function() {
96-
return versions.get()
97+
return manager.load(__dirname)
9798
.then(function(gitbook) {
9899
gitbook.should.be.an.Object();
99100
gitbook.should.have.properties('commands');
@@ -102,19 +103,19 @@ describe('Versions', function() {
102103
});
103104
});
104105

105-
describe('versions.uninstall()', function() {
106+
describe('.uninstall()', function() {
106107
it('should correctly remove a specific version', function() {
107-
return versions.uninstall('2.0.0')
108+
return manager.uninstall('2.0.0')
108109
.then(function() {
109-
var result = versions.list();
110+
var result = manager.versions();
110111
result.should.have.lengthOf(1);
111112
});
112113
});
113114

114115
it('should correctly remove a version by tag', function() {
115-
return versions.uninstall('latest')
116+
return manager.uninstall('latest')
116117
.then(function() {
117-
var result = versions.list();
118+
var result = manager.versions();
118119
result.should.have.lengthOf(0);
119120
});
120121
});

0 commit comments

Comments
 (0)