Skip to content

Commit 7a131e4

Browse files
committed
Replace "should" with "chai"
1 parent 7e54c98 commit 7a131e4

17 files changed

+389
-344
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
},
5050
"devDependencies": {
5151
"c8": "^10.0.0",
52+
"chai": "^6.2.0",
5253
"eslint": "^8.5.0",
5354
"mocha": "^11.0.1",
5455
"nock": "^14.0.0",
55-
"should": "^13.2.3",
5656
"sinon": "^21.0.0"
5757
},
5858
"files": [

test/unit/filename-generator/by-site-structure-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import should from 'should';
1+
import * as chai from 'chai';
2+
chai.should();
3+
24
import '../../utils/assertions.js';
35

46
import sinon from 'sinon';
@@ -75,7 +77,7 @@ describe('FilenameGenerator: bySiteStructure', () => {
7577
const resourceFilename = new Array(1000).fill('a').join('') + '.png';
7678
const r = new Resource('http://example.com/' + resourceFilename);
7779
const filename = bySiteStructureFilenameGenerator(r, options);
78-
should(filename.length).be.lessThan(255);
80+
filename.length.should.be.lessThan(255);
7981
});
8082

8183
it('should shorten filename if resource is html without ext and default name is too long', () => {
@@ -85,7 +87,7 @@ describe('FilenameGenerator: bySiteStructure', () => {
8587
const filepath = bySiteStructureFilenameGenerator(r, { defaultFilename: defaultFilename });
8688
const filenameParts = filepath.split('/');
8789
const filename = filenameParts[filenameParts.length - 1];
88-
should(filename.length).be.lessThan(255);
90+
filename.length.should.be.lessThan(255);
8991
});
9092

9193
it('should return decoded filepath', () => {

test/unit/filename-generator/by-type-test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import should from 'should';
1+
import * as chai from 'chai';
2+
chai.should();
3+
24
import '../../utils/assertions.js';
35

46
import sinon from 'sinon';
@@ -112,7 +114,7 @@ describe('FilenameGenerator: byType', () => {
112114
const resourceFilename = new Array(1000).fill('a').join('') + '.png';
113115
const r = new Resource('http://example.com/a.png', resourceFilename);
114116
const filename = byTypeFilenameGenerator(r, {}, []);
115-
should(filename.length).be.lessThan(255);
117+
filename.length.should.be.lessThan(255);
116118
});
117119

118120
it('should return different short filename if first short filename is occupied', () => {
@@ -122,13 +124,13 @@ describe('FilenameGenerator: byType', () => {
122124
const r2 = new Resource('http://second-example.com/a.png', resourceFilename);
123125

124126
const f1 = byTypeFilenameGenerator(r1, {}, []);
125-
should(f1.length).be.lessThan(255);
127+
f1.length.should.be.lessThan(255);
126128

127129
const f2 = byTypeFilenameGenerator(r2, {}, [ f1 ]);
128-
should(f2.length).be.lessThan(255);
129-
should(f2).not.be.eql(f1);
130+
f2.length.should.be.lessThan(255);
131+
f2.should.not.be.eql(f1);
130132

131-
should(f2).not.be.eql(f1);
133+
f2.should.not.be.eql(f1);
132134
});
133135

134136
it('should return decoded url-based filename', () => {

test/unit/plugins.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as chai from 'chai';
2+
chai.should();
3+
4+
describe('Array', function() {
5+
describe('#indexOf()', function() {
6+
it('should return -1 when the value is not present', function() {
7+
[1,2,3].indexOf(4).should.eql(-1);
8+
});
9+
});
10+
});

test/unit/request-test.js

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import should from 'should';
1+
import * as chai from 'chai';
2+
chai.should();
23
import sinon from 'sinon';
34
import nock from 'nock';
45
import request from '../../lib/request.js';
@@ -28,7 +29,7 @@ describe('request', () => {
2829
};
2930

3031
return request.get({url, options}).then(() => {
31-
scope.isDone().should.be.eql(true);
32+
scope.isDone().should.eql(true);
3233
});
3334
});
3435

@@ -42,7 +43,7 @@ describe('request', () => {
4243
.reply(200);
4344

4445
return request.get({url, referer}).then(() => {
45-
scope.isDone().should.be.eql(true);
46+
scope.isDone().should.eql(true);
4647
});
4748
});
4849

@@ -52,11 +53,11 @@ describe('request', () => {
5253
let handlerStub = sinon.stub().resolves('');
5354

5455
return request.get({url, afterResponse: handlerStub}).then(() => {
55-
scope.isDone().should.be.eql(true);
56-
should(handlerStub.calledOnce).be.eql(true);
56+
scope.isDone().should.eql(true);
57+
handlerStub.calledOnce.should.eql(true);
5758
const afterResponseArgs = handlerStub.getCall(0).args[0];
58-
should(afterResponseArgs.response.body).be.eql('TEST BODY');
59-
should(afterResponseArgs.response.headers).be.eql({});
59+
afterResponseArgs.response.body.should.eql('TEST BODY');
60+
afterResponseArgs.response.headers.should.eql({});
6061
});
6162
});
6263

@@ -71,9 +72,9 @@ describe('request', () => {
7172
});
7273

7374
return request.get({url, afterResponse: handlerStub}).then((data) => {
74-
should(data.body).be.eql('a');
75-
should(data.metadata).be.eql('b');
76-
should(data.encoding).be.eql('utf8');
75+
data.body.should.eql('a');
76+
data.metadata.should.eql('b');
77+
data.encoding.should.eql('utf8');
7778
});
7879
});
7980

@@ -85,9 +86,9 @@ describe('request', () => {
8586
});
8687

8788
return request.get({url, afterResponse: handlerStub}).then((data) => {
88-
should(data.body).be.eql('a');
89-
should(data.metadata).be.eql(null);
90-
should(data.encoding).be.eql('binary');
89+
data.body.should.eql('a');
90+
(data.metadata === null).should.be.true;
91+
data.encoding.should.eql('binary');
9192
});
9293
});
9394

@@ -97,8 +98,8 @@ describe('request', () => {
9798
const handlerStub = sinon.stub().resolves('test body');
9899

99100
return request.get({url, afterResponse: handlerStub}).then((data) => {
100-
should(data.body).be.eql('test body');
101-
should(data.metadata).be.eql(null);
101+
data.body.should.eql('test body');
102+
(data.metadata === null).should.be.true;
102103
});
103104
});
104105

@@ -108,10 +109,10 @@ describe('request', () => {
108109
const handlerStub = sinon.stub().resolves(['1', '2']);
109110

110111
return request.get({url, afterResponse: handlerStub}).then(() => {
111-
should(true).be.eql(false);
112+
true.should.eql(false);
112113
}).catch((e) => {
113-
should(e).be.instanceOf(Error);
114-
should(e.message).match(/Wrong response handler result. Expected string or object, but received/);
114+
e.should.be.instanceOf(Error);
115+
e.message.should.match(/Wrong response handler result. Expected string or object, but received/);
115116
});
116117
});
117118
});
@@ -123,11 +124,13 @@ describe('request', () => {
123124
});
124125

125126
return request.get({url}).then((data) => {
126-
data.should.have.properties(['url', 'body', 'mimeType']);
127-
data.url.should.be.eql('http://www.google.com/');
128-
data.body.should.be.eql('Hello from Google!');
129-
data.mimeType.should.be.eql('text/html');
130-
data.encoding.should.be.eql('utf8');
127+
data.should.have.property('url');
128+
data.should.have.property('body');
129+
data.should.have.property('mimeType');
130+
data.url.should.eql('http://www.google.com/');
131+
data.body.should.eql('Hello from Google!');
132+
data.mimeType.should.eql('text/html');
133+
data.encoding.should.eql('utf8');
131134
});
132135
});
133136

@@ -136,11 +139,11 @@ describe('request', () => {
136139
nock(url).get('/').reply(200, 'Hello from Google!', {});
137140

138141
return request.get({url}).then((data) => {
139-
data.should.have.properties(['url', 'body', 'mimeType']);
140-
data.url.should.be.eql('http://www.google.com/');
141-
data.body.should.be.eql('Hello from Google!');
142-
data.encoding.should.be.eql('binary');
143-
should(data.mimeType).be.eql(null);
142+
data.should.include.all.keys(['url', 'body', 'mimeType', 'encoding']);
143+
data.url.should.eql('http://www.google.com/');
144+
data.body.should.eql('Hello from Google!');
145+
data.encoding.should.eql('binary');
146+
data.should.have.property('mimeType', null);
144147
});
145148
});
146149
});
@@ -149,23 +152,23 @@ describe('get encoding', () => {
149152
it('should return binary by default', () => {
150153
const result = request.getEncoding(null);
151154

152-
should(result).be.eql('binary');
155+
result.should.eql('binary');
153156
});
154157

155158
it('should return binary when no content-type header supplies', () => {
156159
const result = request.getEncoding({
157160
headers: {}
158161
});
159162

160-
should(result).be.eql('binary');
163+
result.should.eql('binary');
161164
});
162165

163166
it('should return binary when content type header doesn\'t include utf-8', () => {
164167
const result = request.getEncoding({
165168
headers: {}
166169
});
167170

168-
should(result).be.eql('binary');
171+
result.should.eql('binary');
169172
});
170173

171174
it('should return binary when content type header doesn\'t include utf-8', () => {
@@ -175,7 +178,7 @@ describe('get encoding', () => {
175178
}
176179
});
177180

178-
should(result).be.eql('binary');
181+
result.should.eql('binary');
179182
});
180183

181184
it('should return utf8 when content type includes utf-8', () => {
@@ -185,15 +188,15 @@ describe('get encoding', () => {
185188
}
186189
});
187190

188-
should(result).be.eql('utf8');
191+
result.should.eql('utf8');
189192
});
190193

191194
it('should return utf8 response object includes it', () => {
192195
const result = request.getEncoding({
193196
encoding: 'utf8'
194197
});
195198

196-
should(result).be.eql('utf8');
199+
result.should.eql('utf8');
197200
});
198201
});
199202

@@ -203,10 +206,10 @@ describe('transformResult', () => {
203206
request.transformResult([1,2,3]);
204207

205208
// We shouldn't get here.
206-
should(true).eql(false);
209+
true.should.eql(false);
207210
} catch (e) {
208-
should(e).be.instanceOf(Error);
209-
should(e.message).eql('Wrong response handler result. Expected string or object, but received array');
211+
e.should.be.instanceOf(Error);
212+
e.message.should.eql('Wrong response handler result. Expected string or object, but received array');
210213
}
211214
});
212215

@@ -215,10 +218,10 @@ describe('transformResult', () => {
215218
request.transformResult(new Error('Oh no'));
216219

217220
// We shouldn't get here.
218-
should(true).eql(false);
221+
true.should.eql(false);
219222
} catch (e) {
220-
should(e).be.instanceOf(Error);
221-
should(e.message).eql('Oh no');
223+
e.should.be.instanceOf(Error);
224+
e.message.should.eql('Oh no');
222225
}
223226
});
224227

@@ -227,10 +230,10 @@ describe('transformResult', () => {
227230
request.transformResult(true);
228231

229232
// We shouldn't get here.
230-
should(true).eql(false);
233+
true.should.eql(false);
231234
} catch (e) {
232-
should(e).be.instanceOf(Error);
233-
should(e.message).eql('Wrong response handler result. Expected string or object, but received boolean');
235+
e.should.be.instanceOf(Error);
236+
e.message.should.eql('Wrong response handler result. Expected string or object, but received boolean');
234237
}
235238
});
236239

@@ -241,9 +244,9 @@ describe('transformResult', () => {
241244
metadata: { foo: 'bar' }
242245
});
243246

244-
should(result).have.property('body', 'SOME BODY');
245-
should(result).have.property('encoding', 'utf8');
246-
should(result).have.property('metadata', { foo: 'bar' });
247+
result.should.have.property('body', 'SOME BODY');
248+
result.should.have.property('encoding', 'utf8');
249+
result.should.have.property('metadata').that.eql({ foo: 'bar' });
247250
});
248251

249252
it('should handle object with empty body string', () => {
@@ -252,38 +255,36 @@ describe('transformResult', () => {
252255
encoding: 'utf8',
253256
});
254257

255-
should(result).have.property('body', '');
256-
should(result).have.property('encoding', 'utf8');
257-
should(result).have.property('metadata', null);
258+
result.should.have.property('body', '');
259+
result.should.have.property('encoding', 'utf8');
260+
result.should.have.property('metadata', null);
258261
});
259262

260263
it('should handle object with defaults and buffer body', () => {
261264
const result = request.transformResult({
262265
body: Buffer.from('SOME BODY'),
263266
});
264267

265-
should(result).have.property('body', 'SOME BODY');
266-
should(result).have.property('encoding', 'binary');
267-
should(result).have.property('metadata', null);
268+
result.should.have.property('body', 'SOME BODY');
269+
result.should.have.property('encoding', 'binary');
270+
result.should.have.property('metadata', null);
268271
});
269272

270273
it('should handle raw string input', () => {
271274
const result = request.transformResult('SOME BODY');
272275

273-
should(result).have.property('body', 'SOME BODY');
274-
should(result).have.property('encoding', 'binary');
275-
should(result).have.property('metadata', null);
276+
result.should.have.property('body', 'SOME BODY');
277+
result.should.have.property('encoding', 'binary');
278+
result.should.have.property('metadata', null);
276279
});
277280

278281
it('should handle null input', () => {
279282
const result = request.transformResult(null);
280-
281-
should(result).eqls(null);
283+
(result === null).should.be.true;
282284
});
283285

284286
it('should handle undefined input', () => {
285287
const result = request.transformResult(undefined);
286-
287-
should(result).eqls(null);
288+
(result === null).should.be.true;
288289
});
289290
});

test/unit/resource-handler/css.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import should from 'should';
1+
import * as chai from 'chai';
2+
chai.should();
23
import sinon from 'sinon';
34
import Resource from '../../../lib/resource.js';
45
import CssResourceHandler from '../../../lib/resource-handler/css/index.js';
@@ -12,8 +13,8 @@ describe('ResourceHandler: Css', () => {
1213
const cssHandler = new CssResourceHandler({}, {downloadChildrenPaths});
1314

1415
return cssHandler.handle(originalResource).then((updatedResource) => {
15-
should(updatedResource).be.equal(originalResource);
16-
should(updatedResource.getText()).be.eql('updated text');
16+
updatedResource.should.be.equal(originalResource);
17+
updatedResource.getText().should.be.eql('updated text');
1718
});
1819
});
1920

@@ -25,8 +26,8 @@ describe('ResourceHandler: Css', () => {
2526
const cssHandler = new CssResourceHandler({}, {downloadChildrenPaths});
2627

2728
return cssHandler.handle(originalResource).then((updatedResource) => {
28-
should(updatedResource).be.equal(originalResource);
29-
should(updatedResource.getEncoding()).be.eql('utf8');
29+
updatedResource.should.be.equal(originalResource);
30+
updatedResource.getEncoding().should.be.eql('utf8');
3031
});
3132
});
3233
});

0 commit comments

Comments
 (0)