Skip to content

Commit

Permalink
updated tests to use trustLocalhost for bypassing broken HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
tejashah88 committed Feb 25, 2019
1 parent 1792d7d commit 011e69f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 46 deletions.
21 changes: 18 additions & 3 deletions README.md
@@ -1,4 +1,4 @@
# SuperTest
# SuperTest

[![Coveralls][coverage-badge]][coverage]
[![Build Status][travis-badge]][travis]
Expand Down Expand Up @@ -81,6 +81,21 @@ describe('GET /user', function() {
});
```

If you need to test with HTTPS against localhost, you can use superagent's `.trustLocalhost()`, which let's you bypass any errors related to broken/insecure HTTPS on localhost.

```js
describe('GET /user', function() {
it('responds with json via HTTPS on localhost', function(done) {
request(app)
.get('/user')
.trustLocalhost()
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
});
```

One thing to note with the above statement is that superagent now sends any HTTP
error (anything other than a 2XX response code) to the callback as the first argument if
you do not add a status code expect (i.e. `.expect(302)`).
Expand Down Expand Up @@ -206,9 +221,9 @@ describe('request.agent(app)', function() {
});
});
```

There is another example that is introduced by the file [agency.js](https://github.com/visionmedia/superagent/blob/master/test/node/agency.js)

Here is an example where 2 cookies are set on the request.

```js
Expand Down
78 changes: 38 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"methods": "^1.1.2",
"superagent": "^3.8.3"
"superagent": "^4.1.0"
},
"devDependencies": {
"body-parser": "^1.18.3",
Expand Down
3 changes: 1 addition & 2 deletions test/supertest.js
Expand Up @@ -8,8 +8,6 @@ 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) {
const app = express();
Expand Down Expand Up @@ -116,6 +114,7 @@ describe('request(app)', function () {

request(server)
.get('/')
.trustLocalhost()
.end(function (err, res) {
if (err) return done(err);
res.status.should.equal(200);
Expand Down

0 comments on commit 011e69f

Please sign in to comment.