-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.spec.js
138 lines (124 loc) · 5.97 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict'
const { semver, semverRange } = require('.')
const Joi = require('joi').extend(semver).extend(semverRange)
const { expect } = require('chai')
describe('semver', function () {
describe('.valid', function () {
it('should accept valid version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().valid())).to.eql('1.2.3')
expect(Joi.attempt('v1.2.3', Joi.semver().valid())).to.eql('v1.2.3')
})
it('should reject invalid version', function () {
expect(function () { Joi.attempt('a.b.c', Joi.semver().valid()) }).to.throw(/"value" needs to be a valid semver expression/)
expect(function () { Joi.attempt('58678', Joi.semver().valid()) }).to.throw(/"value" needs to be a valid semver expression/)
})
})
describe('.gt', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().gt('0.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().gt('2.0.0')) }).to.throw(/"value" needs to be greater than 2\.0\.0/)
})
})
describe('.gte', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().gte('1.2.3'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().gte('2.0.0')) }).to.throw(/"value" needs to be greater than or equal to 2\.0\.0/)
})
})
describe('.lt', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().lt('2.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().lt('1.2.3')) }).to.throw(/"value" needs to be less than 1\.2\.3/)
})
})
describe('.lte', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().lte('1.2.3'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().lte('1.0.0')) }).to.throw(/"value" needs to be less than or equal to 1\.0\.0/)
})
})
describe('.eq', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().eq('1.2.3'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().eq('1.0.0')) }).to.throw(/"value" needs to be logically equivalent to 1\.0\.0/)
})
})
describe('.neq', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().neq('1.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().neq('1.2.3')) }).to.throw(/"value" needs to be logically different than 1\.2\.3/)
})
})
describe('.cmp', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().cmp('=', '1.2.3'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().cmp('=', '1.0.0')) }).to.throw(/"value" needs to satisfy = on 1\.0\.0/)
})
it('should reject invalid params', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().cmp('=', 'x.y.z')) }).to.throw(/exp needs to be a valid semver expression or reference/)
expect(function () { Joi.attempt('1.2.3', Joi.semver().cmp('foo', '1.0.0')) }).to.throw(/cmp needs to be a valid comparator or reference/)
})
})
describe('.satisfies', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().satisfies('^1.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().satisfies('~1.0.0')) }).to.throw(/"value" needs to satisfy ~1\.0\.0/)
})
})
describe('.gtr', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().gtr('~1.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().gtr('^1.0.0')) }).to.throw(/"value" needs to be greater than range \^1\.0\.0/)
})
})
describe('.ltr', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().ltr('~2.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().ltr('^1.2.3')) }).to.throw(/"value" needs to be less than range \^1\.2\.3/)
})
})
describe('outside', function () {
it('should accept version', function () {
expect(Joi.attempt('1.2.3', Joi.semver().outside('<', '~2.0.0'))).to.eql('1.2.3')
expect(Joi.attempt('1.2.3', Joi.semver().outside('>', '~1.0.0'))).to.eql('1.2.3')
})
it('should reject version', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().outside('<', '~1.0.0')) }).to.throw(/"value" needs to be < than range ~1\.0\.0/)
expect(function () { Joi.attempt('1.2.3', Joi.semver().outside('>', '~2.0.0')) }).to.throw(/"value" needs to be > than range ~2\.0\.0/)
})
it('should reject invalid params', function () {
expect(function () { Joi.attempt('1.2.3', Joi.semver().outside('>', 'x.y.z')) }).to.throw(/rng needs to be a valid semver range or reference/)
expect(function () { Joi.attempt('1.2.3', Joi.semver().outside('foo', '~1.0.0')) }).to.throw(/hilo needs to be a valid comparator or reference/)
})
})
})
describe('semverRange', function () {
describe('.valid', function () {
it('should accept valid range', function () {
expect(Joi.attempt('1.2.3 - 1.8.0', Joi.semverRange().valid())).to.eql('1.2.3 - 1.8.0')
})
it('should reject invalid range', function () {
expect(function () { Joi.attempt('a.b.c', Joi.semverRange().valid()) }).to.throw(/"value" needs to be a valid semver range/)
})
})
})