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 'a rack', ->
|
10 | app = null
|
11 | it 'should work with no hash', (done) ->
|
12 | app = express().http()
|
13 | app.use assets = new rack.Rack [
|
14 | new rack.Asset
|
15 | url: '/blank.txt'
|
16 | contents: 'test'
|
17 | new rack.Asset
|
18 | url: '/blank-again.txt'
|
19 | contents: 'test-again'
|
20 | ]
|
21 | app.listen 7076, ->
|
22 | async.parallel [
|
23 | (next) ->
|
24 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
25 | response.headers['content-type'].should.equal 'text/plain'
|
26 | should.not.exist response.headers['cache-control']
|
27 | body.should.equal 'test'
|
28 | next()
|
29 | (next) ->
|
30 | easyrequest 'http://localhost:7076/blank-again.txt', (error, response, body) ->
|
31 | response.headers['content-type'].should.equal 'text/plain'
|
32 | should.not.exist response.headers['cache-control']
|
33 | body.should.equal 'test-again'
|
34 | next()
|
35 | ], done
|
36 |
|
37 | it 'should work with hash', (done) ->
|
38 | app = express().http()
|
39 | app.use new rack.AssetRack [
|
40 | new rack.Asset
|
41 | url: '/blank.txt'
|
42 | contents: 'asset-rack'
|
43 | ]
|
44 | app.listen 7076, ->
|
45 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
46 | response.headers['content-type'].should.equal 'text/plain'
|
47 | response.headers['cache-control'].should.equal 'public, max-age=31536000'
|
48 | body.should.equal 'asset-rack'
|
49 | done()
|
50 |
|
51 | it 'should work with no hash option', (done) ->
|
52 | app = express().http()
|
53 | app.use asset = new rack.AssetRack [
|
54 | new rack.Asset
|
55 | url: '/blank.txt'
|
56 | contents: 'asset-rack'
|
57 | hash: false
|
58 | ]
|
59 | app.listen 7076, ->
|
60 | async.parallel [
|
61 | (next) ->
|
62 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
63 | response.headers['content-type'].should.equal 'text/plain'
|
64 | should.not.exist response.headers['cache-control']
|
65 | body.should.equal 'asset-rack'
|
66 | next()
|
67 | (next) ->
|
68 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
69 | response.statusCode.should.equal 404
|
70 | next()
|
71 | ], done
|
72 |
|
73 | it 'should work with hash option', (done) ->
|
74 | app = express().http()
|
75 | app.use new rack.AssetRack [
|
76 | new rack.Asset
|
77 | url: '/blank.txt'
|
78 | contents: 'asset-rack'
|
79 | hash: true
|
80 | ]
|
81 | app.listen 7076, ->
|
82 | async.parallel [
|
83 | (next) ->
|
84 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
85 | response.headers['content-type'].should.equal 'text/plain'
|
86 | response.headers['cache-control'].should.equal 'public, max-age=31536000'
|
87 | body.should.equal 'asset-rack'
|
88 | next()
|
89 | (next) ->
|
90 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
91 | response.statusCode.should.equal 404
|
92 | next()
|
93 | ], done
|
94 |
|
95 | it 'should set caches', (done) ->
|
96 | app = express().http()
|
97 | app.use new rack.AssetRack [
|
98 | new rack.Asset
|
99 | url: '/blank.txt'
|
100 | contents: 'asset-rack'
|
101 | maxAge: 3600
|
102 | ]
|
103 | app.listen 7076, ->
|
104 | async.parallel [
|
105 | (next) ->
|
106 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
107 | response.headers['content-type'].should.equal 'text/plain'
|
108 | should.not.exist response.headers['cache-control']
|
109 | body.should.equal 'asset-rack'
|
110 | next()
|
111 | (next) ->
|
112 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
113 | response.headers['content-type'].should.equal 'text/plain'
|
114 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
115 | body.should.equal 'asset-rack'
|
116 | next()
|
117 | ], done
|
118 |
|
119 | it 'should set caches with allow no hash option', (done) ->
|
120 | app = express().http()
|
121 | app.use new rack.AssetRack [
|
122 | new rack.Asset
|
123 | url: '/blank.txt'
|
124 | contents: 'asset-rack'
|
125 | maxAge: 3600
|
126 | allowNoHashCache: true
|
127 | ]
|
128 | app.listen 7076, ->
|
129 | async.parallel [
|
130 | (next) ->
|
131 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
132 | response.headers['content-type'].should.equal 'text/plain'
|
133 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
134 | body.should.equal 'asset-rack'
|
135 | next()
|
136 | (next) ->
|
137 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
138 | response.headers['content-type'].should.equal 'text/plain'
|
139 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
140 | body.should.equal 'asset-rack'
|
141 | next()
|
142 | ], done
|
143 |
|
144 | it 'should set caches for globals', (done) ->
|
145 | app = express().http()
|
146 | app.use new rack.AssetRack [
|
147 | new rack.Asset
|
148 | url: '/blank.txt'
|
149 | contents: 'asset-rack'
|
150 | ],
|
151 | maxAge: 3600
|
152 | app.listen 7076, ->
|
153 | async.parallel [
|
154 | (next) ->
|
155 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
156 | response.headers['content-type'].should.equal 'text/plain'
|
157 | should.not.exist response.headers['cache-control']
|
158 | body.should.equal 'asset-rack'
|
159 | next()
|
160 | (next) ->
|
161 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
162 | response.headers['content-type'].should.equal 'text/plain'
|
163 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
164 | body.should.equal 'asset-rack'
|
165 | next()
|
166 | ], done
|
167 |
|
168 | it 'should set caches with allow no hash option for globals', (done) ->
|
169 | app = express().http()
|
170 | app.use new rack.AssetRack [
|
171 | new rack.Asset
|
172 | url: '/blank.txt'
|
173 | contents: 'asset-rack'
|
174 | ],
|
175 | maxAge: 3600
|
176 | allowNoHashCache: true
|
177 | app.listen 7076, ->
|
178 | async.parallel [
|
179 | (next) ->
|
180 | easyrequest 'http://localhost:7076/blank.txt', (error, response, body) ->
|
181 | response.headers['content-type'].should.equal 'text/plain'
|
182 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
183 | body.should.equal 'asset-rack'
|
184 | next()
|
185 | (next) ->
|
186 | easyrequest 'http://localhost:7076/blank-8ac5a0913aa77cb8570e8f2b96e0a1e7.txt', (error, response, body) ->
|
187 | response.headers['content-type'].should.equal 'text/plain'
|
188 | response.headers['cache-control'].should.equal 'public, max-age=3600'
|
189 | body.should.equal 'asset-rack'
|
190 | next()
|
191 | ], done
|
192 |
|
193 | afterEach (done) -> process.nextTick ->
|
194 | app.server.close done
|
195 |
|