forked from bower/bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.js
105 lines (82 loc) · 3.4 KB
/
version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var expect = require('expect.js');
var helpers = require('../helpers');
var version = helpers.require('lib/commands').version;
describe('bower version', function () {
var mainPackage = new helpers.TempDir({
'v0.0.0': {
'bower.json': {
name: 'foobar',
}
}
});
var packageWithoutTags = new helpers.TempDir({});
it('bumps patch version', function() {
mainPackage.prepareGit();
return helpers.run(version, ['patch', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.latestGitTag()).to.be('0.0.1');
});
});
it('bumps minor version', function() {
mainPackage.prepareGit();
return helpers.run(version, ['minor', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.latestGitTag()).to.be('0.1.0');
});
});
it('bumps major version', function() {
mainPackage.prepareGit();
return helpers.run(version, ['major', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.latestGitTag()).to.be('1.0.0');
});
});
it('changes version', function() {
mainPackage.prepareGit();
return helpers.run(version, ['1.2.3', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.latestGitTag()).to.be('1.2.3');
});
});
it('returns the new version', function() {
mainPackage.prepareGit();
return helpers.run(version, ['major', {}, { cwd: mainPackage.path }]).then(function(results) {
expect(results[0]).to.be('1.0.0');
});
});
it('fails on a dirty git repository', function() {
mainPackage.prepareGit();
mainPackage.create({
'dirty.txt': 'This file has not been committed'
});
helpers.run(version, ['patch', {}, { cwd: mainPackage.path }]).then(null, function(err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ENOTGITREPOSITORY');
});
});
it('bumps with custom commit message', function() {
mainPackage.prepareGit();
return helpers.run(version, ['patch', { message: 'Bumping %s, because what'}, { cwd: mainPackage.path }]).then(function() {
var tags = mainPackage.git('tag');
expect(tags).to.be('v0.0.0\nv0.0.1\n');
var message = mainPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('Bumping 0.0.1, because what');
});
});
it('creates commit and tags', function() {
mainPackage.prepareGit();
return helpers.run(version, ['patch', {}, { cwd: mainPackage.path }]).then(function() {
var tags = mainPackage.git('tag');
expect(tags).to.be('v0.0.0\nv0.0.1\n');
var message = mainPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('v0.0.1');
});
});
it('assumes v0.0.0 when no tags exist', function() {
packageWithoutTags.prepareGit();
packageWithoutTags.create({
'index.js': 'console.log("hello, world");'
});
packageWithoutTags.git('add', '-A');
packageWithoutTags.git('commit', '-m"commit"');
return helpers.run(version, ['major', {}, { cwd: packageWithoutTags.path }]).then(function() {
expect(packageWithoutTags.latestGitTag()).to.be('1.0.0');
});
});
});