Skip to content

Commit 1c8338b

Browse files
authoredAug 30, 2023
test: replace should with node:assert (#1782)
1 parent 0dc80d1 commit 1c8338b

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed
 

‎test/node/basic-auth.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
const assert = require('assert');
22
const URL = require('url');
33
const request = require('../support/client');
44
const getSetup = require('../support/setup');
@@ -19,7 +19,7 @@ describe('Basic auth', () => {
1919
new_url.pathname = '/basic-auth';
2020

2121
request.get(URL.format(new_url)).end((error, res) => {
22-
res.status.should.equal(200);
22+
assert.equal(res.status, 200);
2323
done();
2424
});
2525
});
@@ -31,7 +31,7 @@ describe('Basic auth', () => {
3131
.get(`${base}/basic-auth`)
3232
.auth('tobi', 'learnboost')
3333
.end((error, res) => {
34-
res.status.should.equal(200);
34+
assert.equal(res.status, 200);
3535
done();
3636
});
3737
});
@@ -43,7 +43,7 @@ describe('Basic auth', () => {
4343
.get(`${base}/basic-auth/again`)
4444
.auth('tobi')
4545
.end((error, res) => {
46-
res.status.should.eql(200);
46+
assert.equal(res.status, 200);
4747
done();
4848
});
4949
});

‎test/node/basic.js

+40-36
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('[node] request', () => {
3131
describe('with an object', () => {
3232
it('should format the url', () =>
3333
request.get(url.parse(`${base}/login`)).then((res) => {
34-
assert(res.ok);
34+
assert.ok(res.ok);
3535
}));
3636
});
3737

@@ -59,12 +59,13 @@ describe('[node] request', () => {
5959
describe('res.links', () => {
6060
it('should default to an empty object', () =>
6161
request.get(`${base}/login`).then((res) => {
62-
res.links.should.eql({});
62+
assert.deepEqual(res.links, {});
6363
}));
6464

6565
it('should parse the Link header field', (done) => {
6666
request.get(`${base}/links`).end((error, res) => {
67-
res.links.next.should.equal(
67+
assert.equal(
68+
res.links.next,
6869
'https://api.github.com/repos/visionmedia/mocha/issues?page=2'
6970
);
7071
done();
@@ -78,24 +79,24 @@ describe('[node] request', () => {
7879
.post(`${base}/echo`)
7980
.unset('User-Agent')
8081
.end((error, res) => {
81-
assert.equal(void 0, res.header['user-agent']);
82+
assert.equal(res.header['user-agent'], undefined);
8283
done();
8384
});
8485
});
8586
});
8687

8788
describe('case-insensitive', () => {
8889
it('should set/get header fields case-insensitively', () => {
89-
const r = request.post(`${base}/echo`);
90-
r.set('MiXeD', 'helloes');
91-
assert.strictEqual(r.get('mixed'), 'helloes');
90+
const req = request.post(`${base}/echo`);
91+
req.set('MiXeD', 'helloes');
92+
assert.strictEqual(req.get('mixed'), 'helloes');
9293
});
9394

9495
it('should unset header fields case-insensitively', () => {
95-
const r = request.post(`${base}/echo`);
96-
r.set('MiXeD', 'helloes');
97-
r.unset('MIXED');
98-
assert.strictEqual(r.get('mixed'), undefined);
96+
const req = request.post(`${base}/echo`);
97+
req.set('MiXeD', 'helloes');
98+
req.unset('MIXED');
99+
assert.strictEqual(req.get('mixed'), undefined);
99100
});
100101
});
101102

@@ -106,7 +107,7 @@ describe('[node] request', () => {
106107
assert.equal('boolean', typeof request_.write('{"name"'));
107108
assert.equal('boolean', typeof request_.write(':"tobi"}'));
108109
request_.end((error, res) => {
109-
res.text.should.equal('{"name":"tobi"}');
110+
assert.equal(res.text, '{"name":"tobi"}');
110111
done();
111112
});
112113
});
@@ -116,19 +117,21 @@ describe('[node] request', () => {
116117
it('should pipe the response to the given stream', (done) => {
117118
const stream = new EventEmitter();
118119

119-
stream.buf = '';
120+
let buf = '';
120121
stream.writable = true;
121122

122123
stream.write = function (chunk) {
123-
this.buf += chunk;
124+
buf += chunk;
124125
};
125126

126127
stream.end = function () {
127-
this.buf.should.equal('{"name":"tobi"}');
128+
assert.equal(buf, '{"name":"tobi"}');
128129
done();
129130
};
130131

131-
request.post(`${base}/echo`).send('{"name":"tobi"}').pipe(stream);
132+
request.post(`${base}/echo`)
133+
.send('{"name":"tobi"}')
134+
.pipe(stream);
132135
});
133136
});
134137

@@ -140,7 +143,7 @@ describe('[node] request', () => {
140143
.end((error, res) => {
141144
assert.ifError(error);
142145
assert.equal('custom stuff', res.text);
143-
assert(res.buffered);
146+
assert.ok(res.buffered);
144147
done();
145148
});
146149
});
@@ -158,7 +161,7 @@ describe('[node] request', () => {
158161
assert.ifError(error);
159162
assert.equal(res.type, type);
160163
assert.equal(send, res.text);
161-
assert(res.buffered);
164+
assert.ok(res.buffered);
162165
done();
163166
});
164167
});
@@ -174,18 +177,19 @@ describe('[node] request', () => {
174177
.end((error, res) => {
175178
assert.ifError(error);
176179
assert.equal(null, res.text);
177-
res.body.should.eql({});
178-
let buf = '';
180+
assert.deepEqual(res.body, {});
181+
let str = '';
179182
res.setEncoding('utf8');
180183
res.on('data', (chunk) => {
181-
buf += chunk;
184+
str += chunk;
182185
});
183186
res.on('end', () => {
184-
buf.should.equal('hello this is dog');
187+
assert.equal(str, 'hello this is dog');
185188
done();
186189
});
187190
});
188191
});
192+
189193
it("should take precedence over request.buffer['someMimeType'] = true", (done) => {
190194
const type = 'application/foobar';
191195
const send = 'hello this is a dog';
@@ -200,15 +204,15 @@ describe('[node] request', () => {
200204
assert.ifError(error);
201205
assert.equal(null, res.text);
202206
assert.equal(res.type, type);
203-
assert(!res.buffered);
204-
res.body.should.eql({});
205-
let buf = '';
207+
assert.equal(res.buffered, false);
208+
assert.deepEqual(res.body, {});
209+
let str = '';
206210
res.setEncoding('utf8');
207211
res.on('data', (chunk) => {
208-
buf += chunk;
212+
str += chunk;
209213
});
210214
res.on('end', () => {
211-
buf.should.equal(send);
215+
assert.equal(str, send);
212216
done();
213217
});
214218
});
@@ -229,8 +233,8 @@ describe('[node] request', () => {
229233

230234
describe('.agent()', () => {
231235
it('should return the defaut agent', (done) => {
232-
const request_ = request.post(`${base}/echo`);
233-
request_.agent().should.equal(false);
236+
const agent = request.post(`${base}/echo`).agent();
237+
assert.equal(agent, false);
234238
done();
235239
});
236240
});
@@ -239,7 +243,7 @@ describe('[node] request', () => {
239243
it('should set an agent to undefined and ensure it is chainable', (done) => {
240244
const request_ = request.get(`${base}/echo`);
241245
const returnValue = request_.agent(undefined);
242-
returnValue.should.equal(request_);
246+
assert.equal(returnValue, request_);
243247
assert.strictEqual(request_.agent(), undefined);
244248
done();
245249
});
@@ -251,8 +255,8 @@ describe('[node] request', () => {
251255
const request_ = request.get(`${base}/echo`);
252256
const agent = new http.Agent();
253257
const returnValue = request_.agent(agent);
254-
returnValue.should.equal(request_);
255-
request_.agent().should.equal(agent);
258+
assert.equal(returnValue, request_);
259+
assert.equal(request_.agent(), agent);
256260
done();
257261
});
258262
});
@@ -264,9 +268,9 @@ describe('[node] request', () => {
264268
.type('application/x-dog')
265269
.send('hello this is dog')
266270
.then((res) => {
267-
assert.equal(null, res.text);
271+
assert.equal(res.text, null);
268272
assert.equal(res.body.toString(), 'hello this is dog');
269-
res.buffered.should.be.true;
273+
assert.equal(res.buffered, true);
270274
});
271275
});
272276
});
@@ -283,7 +287,7 @@ describe('[node] request', () => {
283287
.buffer(false)
284288
.end((error, res) => {
285289
assert.ifError(error);
286-
assert(!res.buffered);
290+
assert.equal(res.buffered, false);
287291
assert.equal(res.header['content-length'], Buffer.byteLength(img));
288292
done();
289293
});
@@ -313,7 +317,7 @@ describe('[node] request', () => {
313317
.send('wahoo')
314318
.end((error, res) => {
315319
try {
316-
assert.equal('wahoo', res.text);
320+
assert.equal(res.text, 'wahoo');
317321
next();
318322
} catch (err) {
319323
next(err);

0 commit comments

Comments
 (0)
Please sign in to comment.