Skip to content

Commit 0dc80d1

Browse files
authoredAug 27, 2023
test: replace should with node:assert (#1780)
* test: replace should with node:assert * test: rm old should test * test: strict assert don't work in node 10 * test: trigger workflow
1 parent 83e92cb commit 0dc80d1

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed
 

‎test/node/agency.js

+29-32
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
'use strict';
22

3-
require('should-http');
4-
53
const express = require('../support/express');
64

75
const app = express();
86
const request = require('../support/client');
97
const assert = require('assert');
10-
const should = require('should');
118
const cookieParser = require('cookie-parser');
129
const cookiejar = require('cookiejar');
1310
const session = require('express-session');
@@ -90,38 +87,38 @@ describe('request', () => {
9087

9188
it('should gain a session on POST', () =>
9289
agent3.post(`${base}/signin`).then((res) => {
93-
res.should.have.status(200);
94-
should.not.exist(res.headers['set-cookie']);
95-
res.text.should.containEql('dashboard');
90+
assert.equal(res.status, 200);
91+
assert.ok('set-cookie' in res.headers === false);
92+
assert.equal(res.text, 'dashboard');
9693
}));
9794

9895
it('should start with empty session (set cookies)', (done) => {
9996
agent1.get(`${base}/dashboard`).end((error, res) => {
100-
should.exist(error);
101-
res.should.have.status(401);
102-
should.exist(res.headers['set-cookie']);
97+
assert.ok(error instanceof Error);
98+
assert.equal(res.status, 401);
99+
assert.ok('set-cookie' in res.headers);
103100
done();
104101
});
105102
});
106103

107104
it('should gain a session (cookies already set)', () =>
108105
agent1.post(`${base}/signin`).then((res) => {
109-
res.should.have.status(200);
110-
should.not.exist(res.headers['set-cookie']);
111-
res.text.should.containEql('dashboard');
106+
assert.equal(res.status, 200);
107+
assert.ok('set-cookie' in res.headers === false);
108+
assert.equal('dashboard', res.text);
112109
}));
113110

114111
it('should persist cookies across requests', () =>
115112
agent1.get(`${base}/dashboard`).then((res) => {
116-
res.should.have.status(200);
113+
assert.equal(res.status, 200);
117114
}));
118115

119116
it('should have the cookie set in the end callback', () =>
120117
agent4
121118
.post(`${base}/setcookie`)
122119
.then(() => agent4.get(`${base}/getcookie`))
123120
.then((res) => {
124-
res.should.have.status(200);
121+
assert.equal(res.status, 200);
125122
assert.strictEqual(res.text, 'jar');
126123
}));
127124

@@ -147,62 +144,62 @@ describe('request', () => {
147144
it('should send cookies to allowed domain with a different path', () => {
148145
const postRequest = agent4.post(`${base}/x/y/z`)
149146
const cookiesNames = postRequest.cookies.split(';').map(cookie => cookie.split('=')[0])
150-
cookiesNames.should.eql(['cookie', ' connect.sid']);
147+
assert.deepStrictEqual(cookiesNames, ['cookie', ' connect.sid']);
151148
});
152149

153150
it('should not share cookies', (done) => {
154151
agent2.get(`${base}/dashboard`).end((error, res) => {
155-
should.exist(error);
156-
res.should.have.status(401);
152+
assert.ok(error instanceof Error);
153+
assert.equal(res.status, 401);
157154
done();
158155
});
159156
});
160157

161158
it('should not lose cookies between agents', () =>
162159
agent1.get(`${base}/dashboard`).then((res) => {
163-
res.should.have.status(200);
160+
assert.equal(res.status, 200);
164161
}));
165162

166163
it('should be able to follow redirects', () =>
167164
agent1.get(base).then((res) => {
168-
res.should.have.status(200);
169-
res.text.should.containEql('dashboard');
165+
assert.equal(res.status, 200);
166+
assert.equal(res.text, 'dashboard');
170167
}));
171168

172169
it('should be able to post redirects', () =>
173170
agent1
174171
.post(`${base}/redirect`)
175172
.send({ foo: 'bar', baz: 'blaaah' })
176173
.then((res) => {
177-
res.should.have.status(200);
178-
res.text.should.containEql('simple');
179-
res.redirects.should.eql([`${base}/simple`]);
174+
assert.equal(res.status, 200);
175+
assert.equal(res.text, 'simple');
176+
assert.deepStrictEqual(res.redirects, [`${base}/simple`]);
180177
}));
181178

182179
it('should be able to limit redirects', (done) => {
183180
agent1
184181
.get(base)
185182
.redirects(0)
186183
.end((error, res) => {
187-
should.exist(error);
188-
res.should.have.status(302);
189-
res.redirects.should.eql([]);
190-
res.header.location.should.equal('/dashboard');
184+
assert.ok(error instanceof Error);
185+
assert.equal(res.status, 302);
186+
assert.deepEqual(res.redirects, []);
187+
assert.equal(res.header.location, '/dashboard');
191188
done();
192189
});
193190
});
194191

195192
it('should be able to create a new session (clear cookie)', () =>
196193
agent1.post(`${base}/signout`).then((res) => {
197-
res.should.have.status(200);
198-
should.exist(res.headers['set-cookie']);
194+
assert.equal(res.status, 200);
195+
assert.ok('set-cookie' in res.headers);
199196
}));
200197

201198
it('should regenerate with an empty session', (done) => {
202199
agent1.get(`${base}/dashboard`).end((error, res) => {
203-
should.exist(error);
204-
res.should.have.status(401);
205-
should.not.exist(res.headers['set-cookie']);
200+
assert.ok(error instanceof Error);
201+
assert.equal(res.status, 401);
202+
assert.ok('set-cookie' in res.headers === false);
206203
done();
207204
});
208205
});

‎test/node/flags.js

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('flags', () => {
108108
res.unprocessableEntity,
109109
'response should be .unprocessableEntity'
110110
);
111+
111112
done();
112113
});
113114
});

‎test/node/parsers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ describe('req.parse(fn)', () => {
8383

8484
setTimeout(() => {
8585
request_.abort();
86-
}, 50);
86+
}, 150);
8787
});
8888
});

0 commit comments

Comments
 (0)
Please sign in to comment.