tests: remove duplicate utils
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent bc5ca05 · Browse files · 4 files·+40 added−89 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+40 added−89 removed
- tests:+40 added−89 removed
Provenance
- Commit
18f782b- Tree
084eec8- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
bc5ca05
4 files changed+40 added−89 removed
modified:test/res.download.js+10 added-26 removed
1 'use strict'2 3 var after = require('after');4-var assert = require('assert');4 var Buffer = require('safe-buffer').Buffer5 var express = require('..');6 var request = require('supertest');7+var utils = require('./support/utils')8 9 describe('res', function(){10 describe('.download(path)', function(){11 it('should transfer as an attachment', function(done){116 unmodified lines128 })129 })130 131 request(app)132- .get('/')133- .expect(200)134- .expect('Content-Disposition', 'attachment; filename="document"')135- .expect('Cache-Control', 'public, max-age=14400')136- .expect(shouldHaveBody(Buffer.from('tobi')))137- .end(done)132+ .get('/')133+ .expect(200)134+ .expect('Content-Disposition', 'attachment; filename="document"')135+ .expect('Cache-Control', 'public, max-age=14400')136+ .expect(utils.shouldHaveBody(Buffer.from('tobi')))137+ .end(done)138 })139 140 describe('when options.headers contains Content-Disposition', function () {141 it('should be ignored', function (done) {64 unmodified lines206 });207 });208 209 request(app)210- .get('/')211- .expect(shouldNotHaveHeader('Content-Disposition'))212- .expect(200, 'failed', done);210+ .get('/')211+ .expect(utils.shouldNotHaveHeader('Content-Disposition'))212+ .expect(200, 'failed', done)213 })214 })215 })216-217-function shouldHaveBody (buf) {218- return function (res) {219- var body = !Buffer.isBuffer(res.body)220- ? Buffer.from(res.text)221- : res.body222- assert.ok(body, 'response has body')223- assert.strictEqual(body.toString('hex'), buf.toString('hex'))224- }225-}226-227-function shouldNotHaveHeader(header) {228- return function (res) {229- assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);230- };231-}modified:test/res.redirect.js+13 added-20 removed
1 'use strict'2 3-var assert = require('assert')3 var express = require('..');4 var request = require('supertest');5 var utils = require('./support/utils');6 77 unmodified lines84 res.redirect('http://google.com');85 });86 87 request(app)89- .head('/')90- .expect(302)91- .expect('Location', 'http://google.com')92- .expect(shouldNotHaveBody())93- .end(done)88+ .head('/')89+ .expect(302)90+ .expect('Location', 'http://google.com')91+ .expect(utils.shouldNotHaveBody())92+ .end(done)93 })94 })95 96 describe('when accepting html', function(){100 unmodified lines197 res.redirect('http://google.com');198 });199 200 request(app)202- .get('/')203- .set('Accept', 'application/octet-stream')204- .expect(302)205- .expect('location', 'http://google.com')206- .expect('content-length', '0')207- .expect(utils.shouldNotHaveHeader('Content-Type'))208- .expect(shouldNotHaveBody())209- .end(done)201+ .get('/')202+ .set('Accept', 'application/octet-stream')203+ .expect(302)204+ .expect('location', 'http://google.com')205+ .expect('content-length', '0')206+ .expect(utils.shouldNotHaveHeader('Content-Type'))207+ .expect(utils.shouldNotHaveBody())208+ .end(done)209 })210 })211 })213-214-function shouldNotHaveBody () {215- return function (res) {216- assert.ok(res.text === '' || res.text === undefined)217- }218-}modified:test/res.send.js+9 added-25 removed
186 unmodified lines187 res.send(Buffer.from('hello'))188 });189 190 request(app)191- .get('/')192- .expect(200)193- .expect('Content-Type', 'application/octet-stream')194- .expect(shouldHaveBody(Buffer.from('hello')))195- .end(done)191+ .get('/')192+ .expect(200)193+ .expect('Content-Type', 'application/octet-stream')194+ .expect(utils.shouldHaveBody(Buffer.from('hello')))195+ .end(done)196 })197 198 it('should set ETag', function (done) {199 var app = express();58 unmodified lines258 res.send('yay');259 });260 261 request(app)262- .head('/')263- .expect(200)264- .expect(shouldNotHaveBody())265- .end(done)262+ .head('/')263+ .expect(200)264+ .expect(utils.shouldNotHaveBody())265+ .end(done)266 })267 })268 269 describe('when .statusCode is 204', function(){307 unmodified lines577 })578 })579 })580 })581-582-function shouldHaveBody (buf) {583- return function (res) {584- var body = !Buffer.isBuffer(res.body)585- ? Buffer.from(res.text)586- : res.body587- assert.ok(body, 'response has body')588- assert.strictEqual(body.toString('hex'), buf.toString('hex'))589- }590-}591-592-function shouldNotHaveBody () {593- return function (res) {594- assert.ok(res.text === '' || res.text === undefined)595- }596-}modified:test/res.sendFile.js+8 added-18 removed
163 unmodified lines164 it('should accept dotfiles option', function(done){165 var app = createApp(path.resolve(__dirname, 'fixtures/.name'), { dotfiles: 'allow' });166 167 request(app)168- .get('/')169- .expect(200)170- .expect(shouldHaveBody(Buffer.from('tobi')))171- .end(done)168+ .get('/')169+ .expect(200)170+ .expect(utils.shouldHaveBody(Buffer.from('tobi')))171+ .end(done)172 });173 });174 175 describe('with "headers" option', function () {393 unmodified lines569 res.sendfile('test/fixtures/.name', { dotfiles: 'allow' });570 });571 572 request(app)573- .get('/')574- .expect(200)575- .expect(shouldHaveBody(Buffer.from('tobi')))576- .end(done)573+ .get('/')574+ .expect(200)575+ .expect(utils.shouldHaveBody(Buffer.from('tobi')))576+ .end(done)577 })578 579 it('should accept headers option', function(done){580 var app = express();246 unmodified lines827 });828 829 return app;830 }831-832-function shouldHaveBody (buf) {833- return function (res) {834- var body = !Buffer.isBuffer(res.body)835- ? Buffer.from(res.text)836- : res.body837- assert.ok(body, 'response has body')838- assert.strictEqual(body.toString('hex'), buf.toString('hex'))839- }840-}