From 31b6f42609f6c0ec20713a84a6f2ea626e9a49ae Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Sat, 9 Sep 2017 08:50:01 -0400 Subject: [PATCH] Remove --forceExit antipattern by closing all servers in tests --- lib/__tests__/basic-auth.js | 2 +- lib/__tests__/body-parsing.js | 22 +++++++++++----------- lib/__tests__/cache-control.js | 16 ++++++++-------- lib/__tests__/conditional-get.js | 2 +- lib/__tests__/headers.js | 20 ++++++++++---------- lib/__tests__/jsonp.js | 4 ++-- lib/__tests__/object-streams.js | 2 +- lib/__tests__/query-string.js | 4 ++-- lib/middleware/__tests__/middleware.js | 4 ++-- package.json | 2 +- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/__tests__/basic-auth.js b/lib/__tests__/basic-auth.js index ad55931..9ef542f 100644 --- a/lib/__tests__/basic-auth.js +++ b/lib/__tests__/basic-auth.js @@ -8,7 +8,7 @@ describe('Basic Auth', () => { this.body = this.request.basicAuth; }); - return request(app.listen()) + return request(app.callback()) .get('/') .auth('username', 'password') .expect(200) diff --git a/lib/__tests__/body-parsing.js b/lib/__tests__/body-parsing.js index 10355cf..2444bf5 100644 --- a/lib/__tests__/body-parsing.js +++ b/lib/__tests__/body-parsing.js @@ -8,7 +8,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.json(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .send({ message: 'lol' @@ -23,7 +23,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.json(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .type('json') .send('"lol"') @@ -36,7 +36,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.json(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .type('json') .send('"lol"') @@ -51,7 +51,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.urlencoded(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .send('message=lol') .expect(200) @@ -64,7 +64,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.urlencoded(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .type('form') .send({ @@ -83,7 +83,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.urlencoded(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .type('form') .send({ @@ -107,7 +107,7 @@ describe('Body Parsing', () => { this.body = yield * this.request.text(); expect(typeof this.body).toBe('string'); }); - return request(app.listen()) + return request(app.callback()) .post('/') .send('message=lol') .expect(200) @@ -120,7 +120,7 @@ describe('Body Parsing', () => { yield * this.request.text('1kb'); this.body = 204; }); - return request(app.listen()) + return request(app.callback()) .post('/') .send(Buffer.alloc(2048)) .expect(413); @@ -134,7 +134,7 @@ describe('Body Parsing', () => { this.body = yield * this.request.buffer(); expect(Buffer.isBuffer(this.body)).toBeTruthy(); }); - return request(app.listen()) + return request(app.callback()) .post('/') .send('message=lol') .expect(200) @@ -147,7 +147,7 @@ describe('Body Parsing', () => { yield * this.request.buffer('1kb'); this.body = 204; }); - return request(app.listen()) + return request(app.callback()) .post('/') .send(Buffer.alloc(2048)) .expect(413); @@ -160,7 +160,7 @@ describe('Body Parsing', () => { app.use(function * () { this.body = yield * this.request.json(); }); - return request(app.listen()) + return request(app.callback()) .get('/') .set('expect', '100-continue') .set('content-type', 'application/json') diff --git a/lib/__tests__/cache-control.js b/lib/__tests__/cache-control.js index 2c5e8e6..babdf7c 100644 --- a/lib/__tests__/cache-control.js +++ b/lib/__tests__/cache-control.js @@ -10,7 +10,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'public, max-age=1'); @@ -23,7 +23,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'public, max-age=1'); @@ -36,7 +36,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'public, max-age=1'); @@ -51,7 +51,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'public, max-age=1000'); @@ -66,7 +66,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'public, max-age=3600'); @@ -81,7 +81,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'private, no-cache'); @@ -96,7 +96,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(204) .expect('Cache-Control', 'foo'); @@ -111,7 +111,7 @@ describe('Cache-Control', () => { this.status = 204; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(500); }); diff --git a/lib/__tests__/conditional-get.js b/lib/__tests__/conditional-get.js index 132dcbc..f1e9744 100644 --- a/lib/__tests__/conditional-get.js +++ b/lib/__tests__/conditional-get.js @@ -10,7 +10,7 @@ describe('Conditional-Get', () => { this.body = 'hello'; }); - const server = app.listen(); + const server = app.listen().close(); test('should set an etag', () => { return request(server) diff --git a/lib/__tests__/headers.js b/lib/__tests__/headers.js index a97810f..d028227 100644 --- a/lib/__tests__/headers.js +++ b/lib/__tests__/headers.js @@ -6,7 +6,7 @@ describe('Set headers', () => { test('should get X-Response-Time correctly by default', () => { const app = koala(); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('X-Response-Time', /s$/); @@ -18,7 +18,7 @@ describe('Set headers', () => { responseTime: false }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect(res => { @@ -32,7 +32,7 @@ describe('Set headers', () => { test('should not set Strict-Transport-Security by default', () => { const app = koala(); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect(res => { @@ -46,7 +46,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('Strict-Transport-Security', 'max-age=1'); @@ -60,7 +60,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('Strict-Transport-Security', 'max-age=1'); @@ -73,7 +73,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('Strict-Transport-Security', 'max-age=1; includeSubDomains'); @@ -84,7 +84,7 @@ describe('Set headers', () => { test('should get X-Frame-Options DENY by default', () => { const app = koala(); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('X-Frame-Options', 'DENY'); @@ -96,7 +96,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect(res => { @@ -110,7 +110,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('X-Frame-Options', 'DENY'); @@ -122,7 +122,7 @@ describe('Set headers', () => { } }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(404) .expect('X-Frame-Options', 'SAMEORIGIN'); diff --git a/lib/__tests__/jsonp.js b/lib/__tests__/jsonp.js index 8ea5fef..1e413a4 100644 --- a/lib/__tests__/jsonp.js +++ b/lib/__tests__/jsonp.js @@ -12,7 +12,7 @@ describe('jsonp', () => { this.jsonp = {foo: 'bar'}; }); - return request(app.listen()) + return request(app.callback()) .get('/user.json?_callback=fn') .expect(200) .expect('/**/ typeof fn === \'function\' && fn({"foo":"bar"});'); @@ -28,7 +28,7 @@ describe('jsonp', () => { this.jsonp = {foo: 'bar'}; }); - return request(app.listen()) + return request(app.callback()) .get('/user.json') .expect(200) .expect({'foo': 'bar'}); diff --git a/lib/__tests__/object-streams.js b/lib/__tests__/object-streams.js index 07e9fe9..b30044c 100644 --- a/lib/__tests__/object-streams.js +++ b/lib/__tests__/object-streams.js @@ -21,7 +21,7 @@ describe('Object Streams', () => { body.end(); }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect(200) .expect([{ diff --git a/lib/__tests__/query-string.js b/lib/__tests__/query-string.js index 1409b51..b605ecd 100644 --- a/lib/__tests__/query-string.js +++ b/lib/__tests__/query-string.js @@ -9,7 +9,7 @@ describe('Nested Query Strings', () => { this.response.body = this.request.query; }); - return request(app.listen()) + return request(app.callback()) .get('/') .query({ something: { @@ -32,7 +32,7 @@ describe('Nested Query Strings', () => { this.response.body = this.request.query; }); - return request(app.listen()) + return request(app.callback()) .get('/') .query({ something: { diff --git a/lib/middleware/__tests__/middleware.js b/lib/middleware/__tests__/middleware.js index d2fcbf9..37176c9 100644 --- a/lib/middleware/__tests__/middleware.js +++ b/lib/middleware/__tests__/middleware.js @@ -10,7 +10,7 @@ describe('Middlewares', () => { this.body = this.session; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect('{}'); }); @@ -23,7 +23,7 @@ describe('Middlewares', () => { this.body = this.session === undefined; }); - return request(app.listen()) + return request(app.callback()) .get('/') .expect('true'); }); diff --git a/package.json b/package.json index bd5530b..bf538f9 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "template" ], "scripts": { - "tests": "jest --forceExit", + "tests": "jest", "test": "npm-run-all lint tests", "snyk-protect": "snyk protect", "prepare": "npm run snyk-protect",