-
-
Notifications
You must be signed in to change notification settings - Fork 25k
Refactor request tests for clarity and structure #7447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,8 @@ | ||||||||||||
| 'use strict' | ||||||||||||
|
|
||||||||||||
| var after = require('after') | ||||||||||||
| var express = require('../') | ||||||||||||
| , request = require('supertest'); | ||||||||||||
| var request = require('supertest'); | ||||||||||||
|
|
||||||||||||
| describe('app', function(){ | ||||||||||||
| describe('.request', function(){ | ||||||||||||
|
|
@@ -18,15 +18,15 @@ | |||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| request(app) | ||||||||||||
| .get('/foo?name=tobi') | ||||||||||||
| .expect('name=tobi', done); | ||||||||||||
| .get('/foo?name=tobi') | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('name=tobi', done); | ||||||||||||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Otherwise it's just a formatting change. |
||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| it('should only extend for the referenced app', function (done) { | ||||||||||||
| var app1 = express() | ||||||||||||
| var app2 = express() | ||||||||||||
| var cb = after(2, done) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace |
||||||||||||
| app1.request.foobar = function () { | ||||||||||||
| return 'tobi' | ||||||||||||
| } | ||||||||||||
|
|
@@ -36,23 +36,50 @@ | |||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| app2.get('/', function (req, res) { | ||||||||||||
| res.send(req.foobar()) | ||||||||||||
| // This should fail because foobar doesn't exist on app2's request | ||||||||||||
| try { | ||||||||||||
| res.send(req.foobar()) | ||||||||||||
| } catch (err) { | ||||||||||||
| res.status(500).send(err.message) | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+39
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should fail and Express should automatically do what was added here. The Lines 153 to 157 in 023767f
See also |
||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| var completed = 0 | ||||||||||||
| var total = 2 | ||||||||||||
|
|
||||||||||||
| function checkDone() { | ||||||||||||
| completed++ | ||||||||||||
| if (completed === total) { | ||||||||||||
| done() | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+47
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just See also |
||||||||||||
| request(app1) | ||||||||||||
| .get('/') | ||||||||||||
| .expect(200, 'tobi', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('tobi', checkDone) | ||||||||||||
|
Comment on lines
+59
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style only change. See also |
||||||||||||
|
|
||||||||||||
| request(app2) | ||||||||||||
| .get('/') | ||||||||||||
| .expect(500, /(?:not a function|has no method)/, cb) | ||||||||||||
| .expect(500) | ||||||||||||
| .expect(function(res) { | ||||||||||||
| // Check that the error indicates foobar is not a function | ||||||||||||
| var errorMsg = res.text || res.body | ||||||||||||
| if (typeof errorMsg === 'string') { | ||||||||||||
| if (!errorMsg.includes('not a function') && | ||||||||||||
| !errorMsg.includes('has no method') && | ||||||||||||
| !errorMsg.includes('is not a function')) { | ||||||||||||
| throw new Error('Expected error message about missing function, got: ' + errorMsg) | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| }) | ||||||||||||
|
Comment on lines
+65
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing was wrong with the previous check. I have no idea what this is supposed to do. |
||||||||||||
| .end(checkDone) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| it('should inherit to sub apps', function (done) { | ||||||||||||
| var app1 = express() | ||||||||||||
| var app2 = express() | ||||||||||||
| var cb = after(2, done) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||||||||||||
| app1.request.foobar = function () { | ||||||||||||
| return 'tobi' | ||||||||||||
| } | ||||||||||||
|
|
@@ -67,20 +94,32 @@ | |||||||||||
| res.send(req.foobar()) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| var completed = 0 | ||||||||||||
| var total = 2 | ||||||||||||
|
|
||||||||||||
| function checkDone(err) { | ||||||||||||
| if (err) return done(err) | ||||||||||||
| completed++ | ||||||||||||
| if (completed === total) { | ||||||||||||
| done() | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+97
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/') | ||||||||||||
| .expect(200, 'tobi', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('tobi', checkDone) | ||||||||||||
|
Comment on lines
+110
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style only change |
||||||||||||
|
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/sub') | ||||||||||||
| .expect(200, 'tobi', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('tobi', checkDone) | ||||||||||||
|
Comment on lines
+115
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style only change |
||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| it('should allow sub app to override', function (done) { | ||||||||||||
| var app1 = express() | ||||||||||||
| var app2 = express() | ||||||||||||
| var cb = after(2, done) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||||||||||||
| app1.request.foobar = function () { | ||||||||||||
| return 'tobi' | ||||||||||||
| } | ||||||||||||
|
|
@@ -99,20 +138,32 @@ | |||||||||||
| res.send(req.foobar()) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| var completed = 0 | ||||||||||||
| var total = 2 | ||||||||||||
|
|
||||||||||||
| function checkDone(err) { | ||||||||||||
| if (err) return done(err) | ||||||||||||
| completed++ | ||||||||||||
| if (completed === total) { | ||||||||||||
| done() | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+141
to
+151
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/') | ||||||||||||
| .expect(200, 'tobi', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('tobi', checkDone) | ||||||||||||
|
Comment on lines
+154
to
+155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style only change |
||||||||||||
|
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/sub') | ||||||||||||
| .expect(200, 'loki', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('loki', checkDone) | ||||||||||||
|
Comment on lines
+159
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style only change |
||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| it('should not pollute parent app', function (done) { | ||||||||||||
| var app1 = express() | ||||||||||||
| var app2 = express() | ||||||||||||
| var cb = after(2, done) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||||||||||||
| app1.request.foobar = function () { | ||||||||||||
| return 'tobi' | ||||||||||||
| } | ||||||||||||
|
|
@@ -131,13 +182,26 @@ | |||||||||||
| res.send(req.foobar()) | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| var completed = 0 | ||||||||||||
| var total = 2 | ||||||||||||
|
|
||||||||||||
| function checkDone(err) { | ||||||||||||
| if (err) return done(err) | ||||||||||||
| completed++ | ||||||||||||
| if (completed === total) { | ||||||||||||
| done() | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+185
to
+195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/sub') | ||||||||||||
| .expect(200, 'loki', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('loki', checkDone) | ||||||||||||
|
Comment on lines
+198
to
+199
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style only change |
||||||||||||
|
|
||||||||||||
| request(app1) | ||||||||||||
| .get('/sub/foo') | ||||||||||||
| .expect(200, 'tobi', cb) | ||||||||||||
| .expect(200) | ||||||||||||
| .expect('tobi', checkDone) | ||||||||||||
|
Comment on lines
+203
to
+204
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style only change |
||||||||||||
| }) | ||||||||||||
| }) | ||||||||||||
| }) | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style only change