9f27c1c414
change var to const for static require()'d modules make constant var references in app use const keyword refactor context to use es6 constants refactor request to use es6 constants, let block-scope coming next use const in response object for static refs make context tests use es6 constants experimental unit tests -> const use const for static references in unit test over req use const for static refs in res tests update app tests to use const for static refs make the context test use es6 constants for static refs use constants in the README es6 constants seem to work in --harmony on 0.12 too use const's for immutable refs in benchmarks ensure all JS files have blank newline at top add newline to bottom of file where missing add a webchat freenode link to irc channel no need to assign error in catch{}-able test app.silent option to turn off err logging keep test env logging for backwards-compat
70 lines
2 KiB
JavaScript
70 lines
2 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const context = require('../context');
|
|
const assert = require('assert');
|
|
|
|
describe('ctx.type=', function(){
|
|
describe('with a mime', function(){
|
|
it('should set the Content-Type', function(){
|
|
const ctx = context();
|
|
ctx.type = 'text/plain';
|
|
ctx.type.should.equal('text/plain');
|
|
ctx.response.header['content-type'].should.equal('text/plain; charset=utf-8');
|
|
})
|
|
})
|
|
|
|
describe('with an extension', function(){
|
|
it('should lookup the mime', function(){
|
|
const ctx = context();
|
|
ctx.type = 'json';
|
|
ctx.type.should.equal('application/json');
|
|
ctx.response.header['content-type'].should.equal('application/json; charset=utf-8');
|
|
})
|
|
})
|
|
|
|
describe('without a charset', function(){
|
|
it('should default the charset', function(){
|
|
const ctx = context();
|
|
ctx.type = 'text/html';
|
|
ctx.type.should.equal('text/html');
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
|
})
|
|
})
|
|
|
|
describe('with a charset', function(){
|
|
it('should not default the charset', function(){
|
|
const ctx = context();
|
|
ctx.type = 'text/html; charset=foo';
|
|
ctx.type.should.equal('text/html');
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=foo');
|
|
})
|
|
})
|
|
|
|
describe('with an unknown extension', function(){
|
|
it('should default to application/octet-stream',function(){
|
|
const ctx = context();
|
|
ctx.type = 'asdf';
|
|
ctx.type.should.equal('application/octet-stream');
|
|
ctx.response.header['content-type'].should.equal('application/octet-stream');
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('ctx.type', function(){
|
|
describe('with no Content-Type', function(){
|
|
it('should return ""', function(){
|
|
const ctx = context();
|
|
// TODO: this is lame
|
|
assert('' === ctx.type);
|
|
})
|
|
})
|
|
|
|
describe('with a Content-Type', function(){
|
|
it('should return the mime', function(){
|
|
const ctx = context();
|
|
ctx.type = 'json';
|
|
ctx.type.should.equal('application/json');
|
|
})
|
|
})
|
|
})
|