-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
deprecate-test.js
175 lines (154 loc) · 5.46 KB
/
deprecate-test.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'use strict';
const { expect } = require('chai');
const { deprecate } = require('../../../lib/debug');
describe('deprecate', function () {
it('it throws when the description argument is missing', function () {
expect(() => {
deprecate();
}).to.throw('ASSERTION FAILED: When calling `deprecate`, you must provide a description as the first argument.');
expect(() => {
deprecate('');
}).to.throw('ASSERTION FAILED: When calling `deprecate`, you must provide a description as the first argument.');
});
it('it throws when the condition argument is missing', function () {
expect(() => {
deprecate('description');
}).to.throw('ASSERTION FAILED: When calling `deprecate`, you must provide a condition as the second argument.');
});
it('it throws when the options argument is missing', function () {
expect(() => {
deprecate('description', true);
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide an options object as the third argument. The options object must include the `for`, `id`, `since` and `until` options (`url` is optional).'
);
expect(() => {
deprecate('description', undefined);
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide an options object as the third argument. The options object must include the `for`, `id`, `since` and `until` options (`url` is optional).'
);
expect(() => {
deprecate('description', false, null);
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide an options object as the third argument. The options object must include the `for`, `id`, `since` and `until` options (`url` is optional).'
);
});
it('it throws when the `for` option is missing', function () {
expect(() => {
deprecate('description', true, {});
}).to.throw('ASSERTION FAILED: When calling `deprecate`, you must provide the `for` option.');
});
it('it throws when the `id` option is missing', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
});
}).to.throw('ASSERTION FAILED: When calling `deprecate`, you must provide the `id` option.');
});
it('it throws when the `since` option is missing', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
});
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide the `since` option. `since` must include the `available` and/or the `enabled` option.'
);
});
it('it throws when both the `since.available` and `since.enabled` options are missing', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {},
});
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide the `since.available` and/or the `since.enabled` option.'
);
});
it('it throws when the `since.available` option is not a valid SemVer version', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {
available: 'foo',
},
});
}).to.throw('ASSERTION FAILED: `since.available` must be a valid SemVer version.');
});
it('it throws when the `since.enabled` option is not a valid SemVer version', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {
enabled: 'foo',
},
});
}).to.throw('ASSERTION FAILED: `since.enabled` must be a valid SemVer version.');
});
it('it throws when the `until` option is not a valid SemVer version', function () {
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {
available: '4.0.0',
enabled: '4.0.0',
},
});
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide a valid SemVer version for the `until` option.'
);
expect(() => {
deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {
available: '4.0.0',
enabled: '4.0.0',
},
until: 'foo',
});
}).to.throw(
'ASSERTION FAILED: When calling `deprecate`, you must provide a valid SemVer version for the `until` option.'
);
});
it('it does nothing when the condition argument is truthy', function () {
let message = deprecate('description', true, {
for: 'foo',
id: 'foo',
since: {
available: '4.0.0',
enabled: '4.0.0',
},
until: '5.0.0',
});
expect(message).to.be.undefined;
});
it('it displays a deprecation message when the condition argument is falsy', function () {
let message = deprecate('description', false, {
for: 'foo',
id: 'foo',
since: {
available: '4.0.0',
enabled: '4.0.0',
},
until: '5.0.0',
});
expect(message).to.be.equal('DEPRECATION: description [ID: foo]');
});
it('it includes the `url` option in the deprecation message when provided', function () {
let message = deprecate('description', false, {
for: 'foo',
id: 'foo',
since: {
available: '4.0.0',
enabled: '4.0.0',
},
until: '5.0.0',
url: 'https://example.com',
});
expect(message).to.be.equal('DEPRECATION: description [ID: foo] See https://example.com for more details.');
});
});