1 |
|
2 | async = require 'async'
|
3 | should = require('chai').should()
|
4 | rack = require '../.'
|
5 | express = require 'express.io'
|
6 | easyrequest = require 'request'
|
7 | fs = require 'fs'
|
8 |
|
9 | describe 'an asset', ->
|
10 | app = null
|
11 |
|
12 | it 'should work with no hash', (done) ->
|
13 | app = express().http()
|
14 | app.use asset = new rack.Asset
|
15 | url: '/blank.txt',
|
16 | contents: 'asset-rack'
|
17 | app.listen 7076, ->
|
18 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
19 | response.headers['content-type'].should.equal 'text/plain'
|
20 | should.not.exist response.headers['cache-control']
|
21 | body.should.equal 'asset-rack'
|
22 | done()
|
23 |
|
24 | it 'should work with hash', (done) ->
|
25 | app = express().http()
|
26 | app.use new rack.Asset
|
27 | url: '/blank.txt',
|
28 | contents: 'asset-rack'
|
29 | app.listen 7076, ->
|
30 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
31 | response.headers['content-type'].should.equal 'text/plain'
|
32 | response.headers['cache-control'].should.equal 'public, max-age=31536000'
|
33 | body.should.equal 'asset-rack'
|
34 | done()
|
35 |
|
36 | it 'should work with no hash option', (done) ->
|
37 | app = express().http()
|
38 | app.use asset = new rack.Asset
|
39 | url: '/blank.txt',
|
40 | contents: 'asset-rack'
|
41 | hash: false
|
42 | app.listen 7076, ->
|
43 | async.parallel [
|
44 | (next) ->
|
45 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
46 | response.headers['content-type'].should.equal 'text/plain'
|
47 | should.not.exist response.headers['cache-control']
|
48 | body.should.equal 'asset-rack'
|
49 | next()
|
50 | (next) ->
|
51 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
52 | response.statusCode.should.equal 404
|
53 | next()
|
54 | ], done
|
55 |
|
56 | it 'should work with hash option', (done) ->
|
57 | app = express().http()
|
58 | app.use new rack.Asset
|
59 | url: '/blank.txt'
|
60 | contents: 'asset-rack'
|
61 | hash: true
|
62 | app.listen 7076, ->
|
63 | async.parallel [
|
64 | (next) ->
|
65 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
66 | response.statusCode.should.equal 404
|
67 | next()
|
68 | (next) ->
|
69 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
70 | response.headers['content-type'].should.equal 'text/plain'
|
71 | response.headers['cache-control'].should.equal 'public, max-age=31536000'
|
72 | body.should.equal 'asset-rack'
|
73 | next()
|
74 | ], done
|
75 |
|
76 | it 'should set caches', (done) ->
|
77 | app = express().http()
|
78 | app.use new rack.Asset
|
79 | url: '/blank.txt'
|
80 | contents: 'asset-rack'
|
81 | maxAge: 3600
|
82 | app.listen 7076, ->
|
83 | async.parallel [
|
84 | (next) ->
|
85 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
86 | response.headers['content-type'].should.equal 'text/plain'
|
87 | should.not.exist response.headers['cache-control']
|
88 | body.should.equal 'asset-rack'
|
89 | next()
|
90 | (next) ->
|
91 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
92 | response.headers['content-type'].should.equal 'text/plain'
|
93 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
94 | body.should.equal 'asset-rack'
|
95 | next()
|
96 | ], done
|
97 |
|
98 | it 'should set caches with allow no hash option', (done) ->
|
99 | app = express().http()
|
100 | app.use new rack.Asset
|
101 | url: '/blank.txt'
|
102 | contents: 'asset-rack'
|
103 | maxAge: 3600
|
104 | allowNoHashCache: true
|
105 | app.listen 7076, ->
|
106 | async.parallel [
|
107 | (next) ->
|
108 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
109 | response.headers['content-type'].should.equal 'text/plain'
|
110 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
111 | body.should.equal 'asset-rack'
|
112 | next()
|
113 | (next) ->
|
114 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
115 | response.headers['content-type'].should.equal 'text/plain'
|
116 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
117 | body.should.equal 'asset-rack'
|
118 | next()
|
119 | ], done
|
120 |
|
121 | afterEach (done) -> process.nextTick ->
|
122 | app.server.close done
|