Skip to content

Commit ff3a789

Browse files
committedMar 15, 2020
tests: remove shared server object
1 parent 78003f1 commit ff3a789

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed
 

‎test/cookieParser.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,41 @@ var request = require('supertest')
77
var signature = require('cookie-signature')
88

99
describe('cookieParser()', function () {
10-
var server
11-
before(function () {
12-
server = createServer('keyboard cat')
13-
})
14-
15-
after(function (done) {
16-
server.close(done)
17-
})
18-
1910
it('should export JSONCookies function', function () {
2011
assert(typeof cookieParser.JSONCookies, 'function')
2112
})
2213

2314
describe('when no cookies are sent', function () {
2415
it('should default req.cookies to {}', function (done) {
25-
request(server)
16+
request(createServer('keyboard cat'))
2617
.get('/')
2718
.expect(200, '{}', done)
2819
})
2920

3021
it('should default req.signedCookies to {}', function (done) {
31-
request(server)
22+
request(createServer('keyboard cat'))
3223
.get('/signed')
3324
.expect(200, '{}', done)
3425
})
3526
})
3627

3728
describe('when cookies are sent', function () {
3829
it('should populate req.cookies', function (done) {
39-
request(server)
30+
request(createServer('keyboard cat'))
4031
.get('/')
4132
.set('Cookie', 'foo=bar; bar=baz')
4233
.expect(200, '{"foo":"bar","bar":"baz"}', done)
4334
})
4435

4536
it('should inflate JSON cookies', function (done) {
46-
request(server)
37+
request(createServer('keyboard cat'))
4738
.get('/')
4839
.set('Cookie', 'foo=j:{"foo":"bar"}')
4940
.expect(200, '{"foo":{"foo":"bar"}}', done)
5041
})
5142

5243
it('should not inflate invalid JSON cookies', function (done) {
53-
request(server)
44+
request(createServer('keyboard cat'))
5445
.get('/')
5546
.set('Cookie', 'foo=j:{"foo":')
5647
.expect(200, '{"foo":"j:{\\"foo\\":"}', done)
@@ -85,21 +76,22 @@ describe('cookieParser()', function () {
8576
// TODO: "bar" fails...
8677

8778
it('should populate req.signedCookies', function (done) {
88-
request(server)
79+
request(createServer('keyboard cat'))
8980
.get('/signed')
9081
.set('Cookie', 'foo=s:' + val)
9182
.expect(200, '{"foo":"foobarbaz"}', done)
9283
})
9384

9485
it('should remove the signed value from req.cookies', function (done) {
95-
request(server)
86+
request(createServer('keyboard cat'))
9687
.get('/')
9788
.set('Cookie', 'foo=s:' + val)
9889
.expect(200, '{}', done)
9990
})
10091

10192
it('should omit invalid signatures', function (done) {
102-
server.listen()
93+
var server = createServer('keyboard cat')
94+
10395
request(server)
10496
.get('/signed')
10597
.set('Cookie', 'foo=' + val + '3')

0 commit comments

Comments
 (0)