forked from TryGhost/Ghost-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve-version-spec.js
120 lines (98 loc) · 4.35 KB
/
resolve-version-spec.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
const expect = require('chai').expect;
const proxyquire = require('proxyquire');
let resolveVersion;
function stubYarn(result) {
resolveVersion = proxyquire('../../../lib/utils/resolve-version', {
'./yarn': function () {
return Promise.resolve({stdout: result});
}
});
}
describe('Unit: resolveVersion', function () {
it('rejects for versions less than 1.0.0-alpha.1', function () {
stubYarn('');
return resolveVersion('0.11.0').then(function () {
throw new Error('Version finder should not have resolved.');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('Ghost-CLI cannot install versions of Ghost less than 1.0.0');
});
});
it('rejects if result from yarn is invalid JSON', function () {
stubYarn('invalid json');
return resolveVersion().then(function () {
throw new Error('Version finder should not have resolved.');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('Ghost-CLI was unable to load versions from Yarn.');
});
});
it('defaults versions to none', function () {
stubYarn('{}');
return resolveVersion().then(function () {
throw new Error('Version finder should not have resolved.');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('No valid versions found.');
});
});
it('rejects if no versions are found', function () {
stubYarn('{"data": []}');
return resolveVersion().then(function () {
throw new Error('Version finder should not have resolved');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('No valid versions found.');
});
});
describe('without existing version', function () {
it('correctly filters out versions less than 1.0.0-alpha.1', function () {
stubYarn('{"data": ["0.10.1", "0.11.0"]}');
return resolveVersion().then(function () {
throw new Error('Version finder should not have resolved');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('No valid versions found.');
});
});
it('errors if specified version is not in list of valid versions', function () {
stubYarn('{"data": ["1.0.0", "1.0.1"]}');
return resolveVersion('1.0.5').then(function () {
throw new Error('Version finder should not have resolved');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('Invalid version specified: 1.0.5');
});
});
it('resolves with specified version if it exists and is valid', function () {
stubYarn('{"data": ["1.0.0", "1.0.1"]}');
return resolveVersion('1.0.0').then(function (version) {
expect(version).to.equal('1.0.0');
});
});
it('allows a v in front of the version number', function () {
stubYarn('{"data": ["1.0.0", "1.0.1"]}');
return resolveVersion('v1.0.0').then(function (version) {
expect(version).to.equal('1.0.0');
});
});
it('resolves with latest version if no version specified', function () {
stubYarn('{"data": ["1.0.0", "1.0.1"]}');
return resolveVersion().then(function (version) {
expect(version).to.equal('1.0.1');
});
});
});
describe('with existing version', function () {
it('correctly filters out all versions greater than the specified one', function () {
stubYarn('{"data": ["1.0.0", "1.0.1"]}');
return resolveVersion(null, '1.0.1').then(function () {
throw new Error('Version finder should not have resolved');
}).catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('No valid versions found.');
});
});
});
});