Skip to content

Commit 7242805

Browse files
committed
Improve tests for tags
1 parent 5acc085 commit 7242805

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ Use a local folder as a GitBook version (for developement)
9090
```
9191
$ gitbook alias ./mygitbook latest
9292
```
93+
94+
### Resolve
95+
96+
- Look for the `book.json` and use `gitbook` field to resolve versions to use
97+
- Use latest version installed locally
98+
- `3.0.0-pre.1` will be used in favor of `2.6.7` by default
99+
- Tags `pre`, `alpha`, `beta`, `latest` will always be used first

bin/gitbook.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,6 @@ program
7474
);
7575
});
7676

77-
program
78-
.command('ensure [condition] [folder]')
79-
.description('Validate that the version for book match another condition')
80-
.action(function(condition, folder){
81-
runPromise(
82-
manager.ensure(folder || process.cwd(), null, {
83-
install: false
84-
})
85-
.then(function(v) {
86-
if (!tags.satisfies(v.version, condition)) {
87-
throw new Error('Version "' + v.version + '" required by this book doesn\'t match condition "' + condition + '"')
88-
}
89-
}, function() {
90-
throw new Error('Version required by this book doesn\'t match "' + condition + '"');
91-
})
92-
);
93-
});
94-
9577
program
9678
.command('ls-remote')
9779
.description('List remote versions available for install')

test/tags.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,22 @@ describe('Tags', function() {
1717
tags.satisfies('pre', '*').should.be.ok()
1818
});
1919
});
20+
21+
describe('.sort()', function() {
22+
it('should sort tags first', function() {
23+
tags.sort('pre', '1.0.0').should.equal(-1);
24+
tags.sort('beta', '1.0.0').should.equal(-1);
25+
tags.sort('alpha', '1.0.0').should.equal(-1);
26+
});
27+
28+
it('should sort tags correctly', function() {
29+
tags.sort('alpha', 'pre').should.equal(-1);
30+
tags.sort('alpha', 'beta').should.equal(-1);
31+
});
32+
33+
it('should sort pre versions first', function() {
34+
tags.sort('1.0.0-pre.1', '0.0.9').should.equal(-1);
35+
tags.sort('1.0.0-pre.1', '1.0.0').should.equal(1);
36+
});
37+
});
2038
});

0 commit comments

Comments
 (0)