Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace should with node:assert #1780

Merged
merged 4 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions test/node/agency.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';

require('should-http');

const express = require('../support/express');

const app = express();
const request = require('../support/client');
const assert = require('assert');
const should = require('should');
const cookieParser = require('cookie-parser');
const cookiejar = require('cookiejar');
const session = require('express-session');
Expand Down Expand Up @@ -90,38 +87,38 @@ describe('request', () => {

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

it('should start with empty session (set cookies)', (done) => {
agent1.get(`${base}/dashboard`).end((error, res) => {
should.exist(error);
res.should.have.status(401);
should.exist(res.headers['set-cookie']);
assert.ok(error instanceof Error);
assert.equal(res.status, 401);
assert.ok('set-cookie' in res.headers);
done();
});
});

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

it('should persist cookies across requests', () =>
agent1.get(`${base}/dashboard`).then((res) => {
res.should.have.status(200);
assert.equal(res.status, 200);
}));

it('should have the cookie set in the end callback', () =>
agent4
.post(`${base}/setcookie`)
.then(() => agent4.get(`${base}/getcookie`))
.then((res) => {
res.should.have.status(200);
assert.equal(res.status, 200);
assert.strictEqual(res.text, 'jar');
}));

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

it('should not share cookies', (done) => {
agent2.get(`${base}/dashboard`).end((error, res) => {
should.exist(error);
res.should.have.status(401);
assert.ok(error instanceof Error);
assert.equal(res.status, 401);
done();
});
});

it('should not lose cookies between agents', () =>
agent1.get(`${base}/dashboard`).then((res) => {
res.should.have.status(200);
assert.equal(res.status, 200);
}));

it('should be able to follow redirects', () =>
agent1.get(base).then((res) => {
res.should.have.status(200);
res.text.should.containEql('dashboard');
assert.equal(res.status, 200);
assert.equal(res.text, 'dashboard');
}));

it('should be able to post redirects', () =>
agent1
.post(`${base}/redirect`)
.send({ foo: 'bar', baz: 'blaaah' })
.then((res) => {
res.should.have.status(200);
res.text.should.containEql('simple');
res.redirects.should.eql([`${base}/simple`]);
assert.equal(res.status, 200);
assert.equal(res.text, 'simple');
assert.deepStrictEqual(res.redirects, [`${base}/simple`]);
}));

it('should be able to limit redirects', (done) => {
agent1
.get(base)
.redirects(0)
.end((error, res) => {
should.exist(error);
res.should.have.status(302);
res.redirects.should.eql([]);
res.header.location.should.equal('/dashboard');
assert.ok(error instanceof Error);
assert.equal(res.status, 302);
assert.deepEqual(res.redirects, []);
assert.equal(res.header.location, '/dashboard');
done();
});
});

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

it('should regenerate with an empty session', (done) => {
agent1.get(`${base}/dashboard`).end((error, res) => {
should.exist(error);
res.should.have.status(401);
should.not.exist(res.headers['set-cookie']);
assert.ok(error instanceof Error);
assert.equal(res.status, 401);
assert.ok('set-cookie' in res.headers === false);
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions test/node/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('flags', () => {
res.unprocessableEntity,
'response should be .unprocessableEntity'
);

done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/node/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ describe('req.parse(fn)', () => {

setTimeout(() => {
request_.abort();
}, 50);
}, 150);
});
});