From 7233ba6cd801cb3bbd5deec5daab0eaa7116367d Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Wed, 5 Sep 2018 17:10:50 +0200 Subject: [PATCH 1/4] chore(.eslintrc) parserOptions option added to use es6 --- .eslintrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.eslintrc b/.eslintrc index 9095b5ec..3d92c59b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,9 @@ "node": true, "mocha": true }, + "parserOptions": { + "ecmaVersion": 6 + }, "rules": { // disabled - disagree with airbnb "func-names": [0], From 5443136a368e588c750c2c91a29ba5db5799f988 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Wed, 5 Sep 2018 17:11:11 +0200 Subject: [PATCH 2/4] chore(.editorconfig) configuration file created --- .editorconfig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..e85bfad7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +insert_final_newline = true +end_of_line = lf +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.{js,json}] +indent_size = 2 +indent_style = space + +[*.md] +insert_final_newline = false From 82e0828af7b243f3ac4d40ddcc882fdb3ba3866b Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Wed, 5 Sep 2018 17:12:13 +0200 Subject: [PATCH 3/4] refact(test/supertest.js) vars replaced by const and let --- test/supertest.js | 615 +++++++++++++++++++++++----------------------- 1 file changed, 313 insertions(+), 302 deletions(-) diff --git a/test/supertest.js b/test/supertest.js index 19248437..af708780 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -1,45 +1,45 @@ -var request = require('..'); -var https = require('https'); -var fs = require('fs'); -var path = require('path'); -var should = require('should'); -var express = require('express'); -var bodyParser = require('body-parser'); -var cookieParser = require('cookie-parser'); -var nock = require('nock'); +const request = require('..'); +const https = require('https'); +const fs = require('fs'); +const path = require('path'); +const should = require('should'); +const express = require('express'); +const bodyParser = require('body-parser'); +const cookieParser = require('cookie-parser'); +const nock = require('nock'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; -describe('request(url)', function() { - it('should be supported', function(done) { - var app = express(); - var s; +describe('request(url)', function () { + it('should be supported', function (done) { + const app = express(); + let s; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hello'); }); - s = app.listen(function() { - var url = 'http://localhost:' + s.address().port; + s = app.listen(function () { + const url = 'http://localhost:' + s.address().port; request(url) .get('/') .expect('hello', done); }); }); - describe('.end(cb)', function() { - it('should set `this` to the test object when calling cb', function(done) { - var app = express(); - var s; + describe('.end(cb)', function () { + it('should set `this` to the test object when calling cb', function (done) { + const app = express(); + let s; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hello'); }); - s = app.listen(function() { - var url = 'http://localhost:' + s.address().port; - var test = request(url).get('/'); - test.end(function(err, res) { + s = app.listen(function () { + const url = 'http://localhost:' + s.address().port; + const test = request(url).get('/'); + test.end(function (err, res) { this.should.eql(test); done(); }); @@ -48,35 +48,35 @@ describe('request(url)', function() { }); }); -describe('request(app)', function() { - it('should fire up the app on an ephemeral port', function(done) { - var app = express(); +describe('request(app)', function () { + it('should fire up the app on an ephemeral port', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); request(app) .get('/') - .end(function(err, res) { + .end(function (err, res) { res.status.should.equal(200); res.text.should.equal('hey'); done(); }); }); - it('should work with an active server', function(done) { - var app = express(); - var server; + it('should work with an active server', function (done) { + const app = express(); + let server; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); - server = app.listen(4000, function() { + server = app.listen(4000, function () { request(server) .get('/') - .end(function(err, res) { + .end(function (err, res) { res.status.should.equal(200); res.text.should.equal('hey'); done(); @@ -84,17 +84,17 @@ describe('request(app)', function() { }); }); - it('should work with remote server', function(done) { - var app = express(); + it('should work with remote server', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); - app.listen(4001, function() { + app.listen(4001, function () { request('http://localhost:4001') .get('/') - .end(function(err, res) { + .end(function (err, res) { res.status.should.equal(200); res.text.should.equal('hey'); done(); @@ -102,21 +102,21 @@ describe('request(app)', function() { }); }); - it('should work with a https server', function(done) { - var app = express(); - var fixtures = path.join(__dirname, 'fixtures'); - var server = https.createServer({ + it('should work with a https server', function (done) { + const app = express(); + const fixtures = path.join(__dirname, 'fixtures'); + const server = https.createServer({ key: fs.readFileSync(path.join(fixtures, 'test_key.pem')), cert: fs.readFileSync(path.join(fixtures, 'test_cert.pem')) }, app); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); request(server) .get('/') - .end(function(err, res) { + .end(function (err, res) { if (err) return done(err); res.status.should.equal(200); res.text.should.equal('hey'); @@ -124,12 +124,12 @@ describe('request(app)', function() { }); }); - it('should work with .send() etc', function(done) { - var app = express(); + it('should work with .send() etc', function (done) { + const app = express(); app.use(bodyParser.json()); - app.post('/', function(req, res) { + app.post('/', function (req, res) { res.send(req.body.name); }); @@ -139,10 +139,10 @@ describe('request(app)', function() { .expect('john', done); }); - it('should work when unbuffered', function(done) { - var app = express(); + it('should work when unbuffered', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.end('Hello'); }); @@ -151,10 +151,10 @@ describe('request(app)', function() { .expect('Hello', done); }); - it('should default redirects to 0', function(done) { - var app = express(); + it('should default redirects to 0', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.redirect('/login'); }); @@ -163,14 +163,14 @@ describe('request(app)', function() { .expect(302, done); }); - it('should handle redirects', function(done) { - var app = express(); + it('should handle redirects', function (done) { + const app = express(); app.get('/login', function (req, res) { res.end('Login'); }); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.redirect('/login'); }); @@ -185,74 +185,75 @@ describe('request(app)', function() { }); }); - it('should handle socket errors', function(done) { - var app = express(); + it('should handle socket errors', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.destroy(); }); request(app) .get('/') - .end(function(err) { + .end(function (err) { should.exist(err); done(); }); }); - describe('.end(fn)', function() { - it('should close server', function(done) { - var app = express(); - var test; + describe('.end(fn)', function () { + it('should close server', function (done) { + const app = express(); + let test; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('supertest FTW!'); }); test = request(app) .get('/') - .end(function() {}); + .end(function () { + }); - test._server.on('close', function() { + test._server.on('close', function () { done(); }); }); - it('should wait for server to close before invoking fn', function(done) { - var app = express(); - var closed = false; - var test; + it('should wait for server to close before invoking fn', function (done) { + const app = express(); + let closed = false; + let test; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('supertest FTW!'); }); test = request(app) .get('/') - .end(function() { + .end(function () { closed.should.be.true; done(); }); - test._server.on('close', function() { + test._server.on('close', function () { closed = true; }); }); - it('should support nested requests', function(done) { - var app = express(); - var test = request(app); + it('should support nested requests', function (done) { + const app = express(); + const test = request(app); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('supertest FTW!'); }); test .get('/') - .end(function() { + .end(function () { test .get('/') - .end(function(err, res) { + .end(function (err, res) { (err === null).should.be.true; res.status.should.equal(200); res.text.should.equal('supertest FTW!'); @@ -261,19 +262,19 @@ describe('request(app)', function() { }); }); - it('should include the response in the error callback', function(done) { - var app = express(); + it('should include the response in the error callback', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('whatever'); }); request(app) .get('/') - .expect(function() { + .expect(function () { throw new Error('Some error'); }) - .end(function(err, res) { + .end(function (err, res) { should.exist(err); should.exist(res); // Duck-typing response, just in case. @@ -282,18 +283,18 @@ describe('request(app)', function() { }); }); - it('should set `this` to the test object when calling the error callback', function(done) { - var app = express(); - var test; + it('should set `this` to the test object when calling the error callback', function (done) { + const app = express(); + let test; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('whatever'); }); test = request(app).get('/'); - test.expect(function() { + test.expect(function () { throw new Error('Some error'); - }).end(function(err, res) { + }).end(function (err, res) { should.exist(err); this.should.eql(test); done(); @@ -301,17 +302,17 @@ describe('request(app)', function() { }); it('should handle an undefined Response', function (done) { - var app = express(); - var server; + const app = express(); + let server; - app.get('/', function(req, res) { + app.get('/', function (req, res) { setTimeout(function () { res.end(); }, 20); }); - server = app.listen(function() { - var url = 'http://localhost:' + server.address().port; + server = app.listen(function () { + const url = 'http://localhost:' + server.address().port; request(url) .get('/') .timeout(1) @@ -323,15 +324,15 @@ describe('request(app)', function() { }); it('should handle error returned when server goes down', function (done) { - var app = express(); - var server; + const app = express(); + let server; - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.end(); }); - server = app.listen(function() { - var url = 'http://localhost:' + server.address().port; + server = app.listen(function () { + const url = 'http://localhost:' + server.address().port; server.close(); request(url) .get('/') @@ -343,18 +344,18 @@ describe('request(app)', function() { }); }); - describe('.expect(status[, fn])', function() { - it('should assert the response status', function(done) { - var app = express(); + describe('.expect(status[, fn])', function () { + it('should assert the response status', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); request(app) .get('/') .expect(404) - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected 404 "Not Found", got 200 "OK"'); done(); }); @@ -363,7 +364,7 @@ describe('request(app)', function() { describe('.expect(status)', function () { it('should handle connection error', function (done) { - var req = request.agent('http://localhost:1234'); + const req = request.agent('http://localhost:1234'); req .get('/') @@ -377,7 +378,7 @@ describe('request(app)', function() { describe('.expect(status)', function () { it('should assert only status', function (done) { - var app = express(); + const app = express(); app.get('/', function (req, res) { res.send('hey'); @@ -390,11 +391,11 @@ describe('request(app)', function() { }); }); - describe('.expect(status, body[, fn])', function() { - it('should assert the response body and status', function(done) { - var app = express(); + describe('.expect(status, body[, fn])', function () { + it('should assert the response body and status', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('foo'); }); @@ -403,18 +404,18 @@ describe('request(app)', function() { .expect(200, 'foo', done); }); - describe('when the body argument is an empty string', function() { - it('should not quietly pass on failure', function(done) { - var app = express(); + describe('when the body argument is an empty string', function () { + it('should not quietly pass on failure', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('foo'); }); request(app) .get('/') .expect(200, '') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected \'\' response body, got \'foo\''); done(); }); @@ -422,31 +423,31 @@ describe('request(app)', function() { }); }); - describe('.expect(body[, fn])', function() { - it('should assert the response body', function(done) { - var app = express(); + describe('.expect(body[, fn])', function () { + it('should assert the response body', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send({ foo: 'bar' }); }); request(app) .get('/') .expect('hey') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected \'hey\' response body, got \'{"foo":"bar"}\''); done(); }); }); it('should assert the status before the body', function (done) { - var app = express(); + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(500).send({ message: 'something went wrong' }); }); @@ -454,18 +455,18 @@ describe('request(app)', function() { .get('/') .expect(200) .expect('hey') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"'); done(); }); }); - it('should assert the response text', function(done) { - var app = express(); + it('should assert the response text', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send({ foo: 'bar' }); }); @@ -474,19 +475,19 @@ describe('request(app)', function() { .expect('{"foo":"bar"}', done); }); - it('should assert the parsed response body', function(done) { - var app = express(); + it('should assert the parsed response body', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send({ foo: 'bar' }); }); request(app) .get('/') .expect({ foo: 'baz' }) - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }'); request(app) @@ -497,7 +498,7 @@ describe('request(app)', function() { }); it('should test response object types', function (done) { - var app = express(); + const app = express(); app.get('/', function (req, res) { res.status(200).json({ stringValue: 'foo', numberValue: 3 }); }); @@ -508,7 +509,7 @@ describe('request(app)', function() { }); it('should deep test response object types', function (done) { - var app = express(); + const app = express(); app.get('/', function (req, res) { res.status(200) .json({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: '5' } }); @@ -517,7 +518,7 @@ describe('request(app)', function() { request(app) .get('/') .expect({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: 5 } }) - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected { stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: 5 } } response body, got { stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: \'5\' } }'); // eslint-disable-line max-len request(app) @@ -527,26 +528,26 @@ describe('request(app)', function() { }); }); - it('should support regular expressions', function(done) { - var app = express(); + it('should support regular expressions', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('foobar'); }); request(app) .get('/') .expect(/^bar/) - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected body \'foobar\' to match /^bar/'); done(); }); }); - it('should assert response body multiple times', function(done) { - var app = express(); + it('should assert response body multiple times', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey tj'); }); @@ -561,10 +562,10 @@ describe('request(app)', function() { }); }); - it('should assert response body multiple times with no exception', function(done) { - var app = express(); + it('should assert response body multiple times with no exception', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey tj'); }); @@ -576,44 +577,44 @@ describe('request(app)', function() { }); }); - describe('.expect(field, value[, fn])', function() { - it('should assert the header field presence', function(done) { - var app = express(); + describe('.expect(field, value[, fn])', function () { + it('should assert the header field presence', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send({ foo: 'bar' }); }); request(app) .get('/') .expect('Content-Foo', 'bar') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected "Content-Foo" header field'); done(); }); }); - it('should assert the header field value', function(done) { - var app = express(); + it('should assert the header field value', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send({ foo: 'bar' }); }); request(app) .get('/') .expect('Content-Type', 'text/html') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected "Content-Type" of "text/html", ' - + 'got "application/json; charset=utf-8"'); + + 'got "application/json; charset=utf-8"'); done(); }); }); - it('should assert multiple fields', function(done) { - var app = express(); + it('should assert multiple fields', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); @@ -624,60 +625,60 @@ describe('request(app)', function() { .end(done); }); - it('should support regular expressions', function(done) { - var app = express(); + it('should support regular expressions', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); request(app) .get('/') .expect('Content-Type', /^application/) - .end(function(err) { + .end(function (err) { err.message.should.equal('expected "Content-Type" matching /^application/, ' - + 'got "text/html; charset=utf-8"'); + + 'got "text/html; charset=utf-8"'); done(); }); }); - it('should support numbers', function(done) { - var app = express(); + it('should support numbers', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); request(app) .get('/') .expect('Content-Length', 4) - .end(function(err) { + .end(function (err) { err.message.should.equal('expected "Content-Length" of "4", got "3"'); done(); }); }); - describe('handling arbitrary expect functions', function() { - var app; - var get; + describe('handling arbitrary expect functions', function () { + let app; + let get; - before(function() { + before(function () { app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send('hey'); }); }); - beforeEach(function() { + beforeEach(function () { get = request(app).get('/'); }); - it('reports errors', function(done) { + it('reports errors', function (done) { get - .expect(function(res) { + .expect(function (res) { throw new Error('failed'); }) - .end(function(err) { + .end(function (err) { err.message.should.equal('failed'); done(); }); @@ -685,44 +686,51 @@ describe('request(app)', function() { it( 'ensures truthy non-errors returned from asserts are not promoted to errors', - function(done) { + function (done) { get - .expect(function(res) { + .expect(function (res) { return 'some descriptive error'; }) - .end(function(err) { + .end(function (err) { should.not.exist(err); done(); }); } ); - it('ensures truthy errors returned from asserts are throw to end', function(done) { + it('ensures truthy errors returned from asserts are throw to end', function (done) { get - .expect(function(res) { + .expect(function (res) { return new Error('some descriptive error'); }) - .end(function(err) { + .end(function (err) { err.message.should.equal('some descriptive error'); (err instanceof Error).should.be.true; done(); }); }); - it("doesn't create false negatives", function(done) { + it("doesn't create false negatives", function (done) { get - .expect(function(res) {}) + .expect(function (res) { + }) .end(done); }); - it('handles multiple asserts', function(done) { - var calls = []; + it('handles multiple asserts', function (done) { + const calls = []; get - .expect(function(res) { calls[0] = 1; }) - .expect(function(res) { calls[1] = 1; }) - .expect(function(res) { calls[2] = 1; }) - .end(function() { - var callCount = [0, 1, 2].reduce(function(count, i) { + .expect(function (res) { + calls[0] = 1; + }) + .expect(function (res) { + calls[1] = 1; + }) + .expect(function (res) { + calls[2] = 1; + }) + .end(function () { + const callCount = [0, 1, 2].reduce(function (count, i) { return count + calls[i]; }, 0); callCount.should.equal(3, "didn't see all assertions run"); @@ -730,30 +738,33 @@ describe('request(app)', function() { }); }); - it('plays well with normal assertions - no false positives', function(done) { + it('plays well with normal assertions - no false positives', function (done) { get - .expect(function(res) {}) + .expect(function (res) { + }) .expect('Content-Type', /json/) - .end(function(err) { + .end(function (err) { err.message.should.match(/Content-Type/); done(); }); }); - it('plays well with normal assertions - no false negatives', function(done) { + it('plays well with normal assertions - no false negatives', function (done) { get - .expect(function(res) {}) + .expect(function (res) { + }) .expect('Content-Type', /html/) - .expect(function(res) {}) + .expect(function (res) { + }) .expect('Content-Type', /text/) .end(done); }); }); - describe('handling multiple assertions per field', function() { - it('should work', function(done) { - var app = express(); - app.get('/', function(req, res) { + describe('handling multiple assertions per field', function () { + it('should work', function (done) { + const app = express(); + app.get('/', function (req, res) { res.send('hey'); }); @@ -764,9 +775,9 @@ describe('request(app)', function() { .end(done); }); - it('should return an error if the first one fails', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('should return an error if the first one fails', function (done) { + const app = express(); + app.get('/', function (req, res) { res.send('hey'); }); @@ -774,16 +785,16 @@ describe('request(app)', function() { .get('/') .expect('Content-Type', /bloop/) .expect('Content-Type', /html/) - .end(function(err) { + .end(function (err) { err.message.should.equal('expected "Content-Type" matching /bloop/, ' - + 'got "text/html; charset=utf-8"'); + + 'got "text/html; charset=utf-8"'); done(); }); }); - it('should return an error if a middle one fails', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('should return an error if a middle one fails', function (done) { + const app = express(); + app.get('/', function (req, res) { res.send('hey'); }); @@ -792,16 +803,16 @@ describe('request(app)', function() { .expect('Content-Type', /text/) .expect('Content-Type', /bloop/) .expect('Content-Type', /html/) - .end(function(err) { + .end(function (err) { err.message.should.equal('expected "Content-Type" matching /bloop/, ' - + 'got "text/html; charset=utf-8"'); + + 'got "text/html; charset=utf-8"'); done(); }); }); - it('should return an error if the last one fails', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('should return an error if the last one fails', function (done) { + const app = express(); + app.get('/', function (req, res) { res.send('hey'); }); @@ -810,9 +821,9 @@ describe('request(app)', function() { .expect('Content-Type', /text/) .expect('Content-Type', /html/) .expect('Content-Type', /bloop/) - .end(function(err) { + .end(function (err) { err.message.should.equal('expected "Content-Type" matching /bloop/, ' - + 'got "text/html; charset=utf-8"'); + + 'got "text/html; charset=utf-8"'); done(); }); }); @@ -820,58 +831,58 @@ describe('request(app)', function() { }); }); -describe('request.agent(app)', function() { - var app = express(); - var agent = request.agent(app); +describe('request.agent(app)', function () { + const app = express(); + const agent = request.agent(app); app.use(cookieParser()); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.cookie('cookie', 'hey'); res.send(); }); - app.get('/return', function(req, res) { + app.get('/return', function (req, res) { if (req.cookies.cookie) res.send(req.cookies.cookie); else res.send(':('); }); - it('should save cookies', function(done) { + it('should save cookies', function (done) { agent .get('/') .expect('set-cookie', 'cookie=hey; Path=/', done); }); - it('should send cookies', function(done) { + it('should send cookies', function (done) { agent .get('/return') .expect('hey', done); }); }); -describe('agent.host(host)', function() { - it('should set request hostname', function(done) { - var app = express(); - var agent = request.agent(app); +describe('agent.host(host)', function () { + it('should set request hostname', function (done) { + const app = express(); + const agent = request.agent(app); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.send(); }); agent .host('something.test') .get('/') - .end(function(err, res) { + .end(function (err, res) { err.hostname.should.equal('something.test'); done(); }); }); }); -describe('. works as expected', function() { +describe('. works as expected', function () { it('.delete should work', function (done) { - var app = express(); - app.delete('/', function(req, res) { + const app = express(); + app.delete('/', function (req, res) { res.sendStatus(200); }); @@ -880,8 +891,8 @@ describe('. works as expected', function() { .expect(200, done); }); it('.del should work', function (done) { - var app = express(); - app.delete('/', function(req, res) { + const app = express(); + app.delete('/', function (req, res) { res.sendStatus(200); }); @@ -890,8 +901,8 @@ describe('. works as expected', function() { .expect(200, done); }); it('.get should work', function (done) { - var app = express(); - app.get('/', function(req, res) { + const app = express(); + app.get('/', function (req, res) { res.sendStatus(200); }); @@ -900,8 +911,8 @@ describe('. works as expected', function() { .expect(200, done); }); it('.post should work', function (done) { - var app = express(); - app.post('/', function(req, res) { + const app = express(); + app.post('/', function (req, res) { res.sendStatus(200); }); @@ -910,8 +921,8 @@ describe('. works as expected', function() { .expect(200, done); }); it('.put should work', function (done) { - var app = express(); - app.put('/', function(req, res) { + const app = express(); + app.put('/', function (req, res) { res.sendStatus(200); }); @@ -920,8 +931,8 @@ describe('. works as expected', function() { .expect(200, done); }); it('.head should work', function (done) { - var app = express(); - app.head('/', function(req, res) { + const app = express(); + app.head('/', function (req, res) { res.statusCode = 200; res.set('Content-Encoding', 'gzip'); res.set('Content-Length', '1024'); @@ -941,13 +952,13 @@ describe('. works as expected', function() { }); }); -describe('assert ordering by call order', function() { - it('should assert the body before status', function(done) { - var app = express(); +describe('assert ordering by call order', function () { + it('should assert the body before status', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(500).json({ message: 'something went wrong' }); }); @@ -955,19 +966,19 @@ describe('assert ordering by call order', function() { .get('/') .expect('hey') .expect(200) - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected \'hey\' response body, ' + 'got \'{"message":"something went wrong"}\''); done(); }); }); - it('should assert the status before body', function(done) { - var app = express(); + it('should assert the status before body', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(500).json({ message: 'something went wrong' }); }); @@ -975,18 +986,18 @@ describe('assert ordering by call order', function() { .get('/') .expect(200) .expect('hey') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"'); done(); }); }); - it('should assert the fields before body and status', function(done) { - var app = express(); + it('should assert the fields before body and status', function (done) { + const app = express(); app.set('json spaces', 0); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(200).json({ hello: 'world' }); }); @@ -994,30 +1005,30 @@ describe('assert ordering by call order', function() { .get('/') .expect('content-type', /html/) .expect('hello') - .end(function(err, res) { + .end(function (err, res) { err.message.should.equal('expected "content-type" matching /html/, ' + 'got "application/json; charset=utf-8"'); done(); }); }); - it('should call the expect function in order', function(done) { - var app = express(); + it('should call the expect function in order', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(200).json({}); }); request(app) .get('/') - .expect(function(res) { + .expect(function (res) { res.body.first = 1; }) - .expect(function(res) { + .expect(function (res) { (res.body.first === 1).should.be.true; res.body.second = 2; }) - .end(function(err, res) { + .end(function (err, res) { if (err) return done(err); (res.body.first === 1).should.be.true; (res.body.second === 2).should.be.true; @@ -1025,29 +1036,29 @@ describe('assert ordering by call order', function() { }); }); - it('should call expect(fn) and expect(status, fn) in order', function(done) { - var app = express(); + it('should call expect(fn) and expect(status, fn) in order', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(200).json({}); }); request(app) .get('/') - .expect(function(res) { + .expect(function (res) { res.body.first = 1; }) - .expect(200, function(err, res) { + .expect(200, function (err, res) { (err === null).should.be.true; (res.body.first === 1).should.be.true; done(); }); }); - it('should call expect(fn) and expect(header,value) in order', function(done) { - var app = express(); + it('should call expect(fn) and expect(header,value) in order', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res .set('X-Some-Header', 'Some value') .send(); @@ -1056,29 +1067,29 @@ describe('assert ordering by call order', function() { request(app) .get('/') .expect('X-Some-Header', 'Some value') - .expect(function(res) { + .expect(function (res) { res.headers['x-some-header'] = ''; }) .expect('X-Some-Header', '') .end(done); }); - it('should call expect(fn) and expect(body) in order', function(done) { - var app = express(); + it('should call expect(fn) and expect(body) in order', function (done) { + const app = express(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.json({ somebody: 'some body value' }); }); request(app) .get('/') .expect(/some body value/) - .expect(function(res) { + .expect(function (res) { res.body.somebody = 'nobody'; }) .expect(/some body value/) // res.text should not be modified. .expect({ somebody: 'nobody' }) - .expect(function(res) { + .expect(function (res) { res.text = 'gone'; }) .expect('gone') @@ -1088,85 +1099,85 @@ describe('assert ordering by call order', function() { }); }); -describe('request.get(url).query(vals) works as expected', function() { - it('normal single query string value works', function(done) { - var app = express(); - app.get('/', function(req, res) { +describe('request.get(url).query(vals) works as expected', function () { + it('normal single query string value works', function (done) { + const app = express(); + app.get('/', function (req, res) { res.status(200).send(req.query.val); }); request(app) .get('/') .query({ val: 'Test1' }) - .expect(200, function(err, res) { + .expect(200, function (err, res) { res.text.should.be.equal('Test1'); done(); }); }); - it('array query string value works', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('array query string value works', function (done) { + const app = express(); + app.get('/', function (req, res) { res.status(200).send(Array.isArray(req.query.val)); }); request(app) .get('/') .query({ 'val[]': ['Test1', 'Test2'] }) - .expect(200, function(err, res) { + .expect(200, function (err, res) { res.req.path.should.be.equal('/?val%5B%5D=Test1&val%5B%5D=Test2'); res.text.should.be.equal('true'); done(); }); }); - it('array query string value work even with single value', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('array query string value work even with single value', function (done) { + const app = express(); + app.get('/', function (req, res) { res.status(200).send(Array.isArray(req.query.val)); }); request(app) .get('/') .query({ 'val[]': ['Test1'] }) - .expect(200, function(err, res) { + .expect(200, function (err, res) { res.req.path.should.be.equal('/?val%5B%5D=Test1'); res.text.should.be.equal('true'); done(); }); }); - it('object query string value works', function(done) { - var app = express(); - app.get('/', function(req, res) { + it('object query string value works', function (done) { + const app = express(); + app.get('/', function (req, res) { res.status(200).send(req.query.val.test); }); request(app) .get('/') .query({ val: { test: 'Test1' } }) - .expect(200, function(err, res) { + .expect(200, function (err, res) { res.text.should.be.equal('Test1'); done(); }); }); - it('handles unknown errors', function(done) { - var app = express(); + it('handles unknown errors', function (done) { + const app = express(); nock.disableNetConnect(); - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.status(200).send('OK'); }); request(app) .get('/') - // This expect should never get called, but exposes this issue with other - // errors being obscured by the response assertions - // https://github.com/visionmedia/supertest/issues/352 + // This expect should never get called, but exposes this issue with other + // errors being obscured by the response assertions + // https://github.com/visionmedia/supertest/issues/352 .expect(200) - .end(function(err, res) { + .end(function (err, res) { err.should.be.an.instanceof(Error); err.message.should.match(/Nock: Not allow net connect/); done(); From 913150dcc343d2d701db0950f2886985a3564992 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Wed, 5 Sep 2018 18:56:39 +0200 Subject: [PATCH 4/4] chore(.editorconfig) [*.md] block removed --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index e85bfad7..5cd5590f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,3 @@ indent_size = 2 [*.{js,json}] indent_size = 2 indent_style = space - -[*.md] -insert_final_newline = false