Skip to content

Commit

Permalink
test: replace should with node:assert (#1780)
Browse files Browse the repository at this point in the history
* test: replace should with node:assert

* test: rm old should test

* test: strict assert don't work in node 10

* test: trigger workflow
  • Loading branch information
jimmywarting authored Aug 27, 2023
1 parent 83e92cb commit 0dc80d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
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);
});
});

0 comments on commit 0dc80d1

Please sign in to comment.