spec.plugins.static.js
This file
Path
spec/spec.plugins.static.js
78 lines · 2.6 KiB · JavaScript
Last changed by
Merge branch 'async-cache'visionmediabefore adoption7606f1b
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
describe 'Express' describe 'StaticFile' before StaticFile = require('express/plugins/static').File use(require('express/plugins/static').Static, { path: 'spec/fixtures' }) end describe '#constructor' it 'should accept and assign #path' (new StaticFile('/foo/bar')).path.should.eql '/foo/bar' end it 'should throw an InvalidPathError when .. is found' // TODO: use throw_error when fixed... try { new StaticFile('/../foobar') } catch (e) { e.name.should.eql 'InvalidPathError' e.message.should.eql "`/../foobar' is not a valid path" } end end describe 'GET /public/*' it 'should transfer static files' get('/public/user.json').body.should.include '"name":' end end describe '#sendfile()' describe 'when the file exists' it 'should transfer the file' get('/public/*', function(file){ this.sendfile('spec/fixtures/' + file) }) get('/public/user.json').body.should.include '"name":' end it 'should automatically set the content type based on extension' get('/public/*', function(file){ this.sendfile('spec/fixtures/' + file) }) get('/public/user.json').headers['content-type'].should.eql 'application/json' end end describe 'when "cache static files" is enabled' it 'should transfer the file' enable('cache static files') get('/public/*', function(file){ this.sendfile('spec/fixtures/' + file) }) get('/cached', function(){ var self = this this.cache.get('static:spec/fixtures/user.json', function(val){ self.halt(200, val ? 'yes' : 'no') }) }) get('/cached').body.should.eql 'no' get('/public/user.json').body.should.include '"name":' get('/cached').body.should.eql 'yes' get('/cached').body.should.eql 'yes' end it 'should automatically set the content type based on extension' enable('cache static files') get('/public/*', function(file){ this.sendfile('spec/fixtures/' + file) }) get('/public/user.json').headers['content-type'].should.eql 'application/json' get('/public/user.json').headers['content-type'].should.eql 'application/json' get('/public/user.json').headers['content-type'].should.eql 'application/json' end end end endend