Skip to content
Myr

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

4 files+40 added−89 removed

modified:test/res.download.js+10 added-26 removed
1'use strict'23var after = require('after');4var assert = require('assert');4var Buffer = require('safe-buffer').Buffer5var express = require('..');6var request = require('supertest');7var utils = require('./support/utils')89describe('res', function(){10 describe('.download(path)', function(){11 it('should transfer as an attachment', function(done){
116 unmodified lines
128 })129 })130131 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 })139140 describe('when options.headers contains Content-Disposition', function () {141 it('should be ignored', function (done) {
64 unmodified lines
206 });207 });208209 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})216217function 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}226227function 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'23var assert = require('assert')3var express = require('..');4var request = require('supertest');5var utils = require('./support/utils');6
77 unmodified lines
84 res.redirect('http://google.com');85 });8687 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 })9596 describe('when accepting html', function(){
100 unmodified lines
197 res.redirect('http://google.com');198 });199200 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})213214function 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 lines
187 res.send(Buffer.from('hello'))188 });189190 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 })197198 it('should set ETag', function (done) {199 var app = express();
58 unmodified lines
258 res.send('yay');259 });260261 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 })268269 describe('when .statusCode is 204', function(){
307 unmodified lines
577 })578 })579 })580})581582function 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}591592function 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 lines
164 it('should accept dotfiles option', function(done){165 var app = createApp(path.resolve(__dirname, 'fixtures/.name'), { dotfiles: 'allow' });166167 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 });174175 describe('with "headers" option', function () {
393 unmodified lines
569 res.sendfile('test/fixtures/.name', { dotfiles: 'allow' });570 });571572 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 })578579 it('should accept headers option', function(done){580 var app = express();
246 unmodified lines
827 });828829 return app;830}831832function 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}