-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathtest.js
More file actions
227 lines (180 loc) · 8.71 KB
/
test.js
File metadata and controls
227 lines (180 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
var assert = require('assert')
var mimeTypes = require('..')
describe('mimeTypes', function () {
describe('.charset(type)', function () {
it('should return "UTF-8" for "application/json"', function () {
assert.strictEqual(mimeTypes.charset('application/json'), 'UTF-8')
})
it('should return "UTF-8" for "application/json; foo=bar"', function () {
assert.strictEqual(mimeTypes.charset('application/json; foo=bar'), 'UTF-8')
})
it('should return "UTF-8" for "application/javascript"', function () {
assert.strictEqual(mimeTypes.charset('application/javascript'), 'UTF-8')
})
it('should return "UTF-8" for "application/JavaScript"', function () {
assert.strictEqual(mimeTypes.charset('application/JavaScript'), 'UTF-8')
})
it('should return "UTF-8" for "text/html"', function () {
assert.strictEqual(mimeTypes.charset('text/html'), 'UTF-8')
})
it('should return "UTF-8" for "TEXT/HTML"', function () {
assert.strictEqual(mimeTypes.charset('TEXT/HTML'), 'UTF-8')
})
it('should return "UTF-8" for any text/*', function () {
assert.strictEqual(mimeTypes.charset('text/x-bogus'), 'UTF-8')
})
it('should return false for unknown types', function () {
assert.strictEqual(mimeTypes.charset('application/x-bogus'), false)
})
it('should return false for any application/octet-stream', function () {
assert.strictEqual(mimeTypes.charset('application/octet-stream'), false)
})
it('should return false for invalid arguments', function () {
assert.strictEqual(mimeTypes.charset({}), false)
assert.strictEqual(mimeTypes.charset(null), false)
assert.strictEqual(mimeTypes.charset(true), false)
assert.strictEqual(mimeTypes.charset(42), false)
})
})
describe('.contentType(extension)', function () {
it('should return content-type for "html"', function () {
assert.strictEqual(mimeTypes.contentType('html'), 'text/html; charset=utf-8')
})
it('should return content-type for ".html"', function () {
assert.strictEqual(mimeTypes.contentType('.html'), 'text/html; charset=utf-8')
})
it('should return content-type for "jade"', function () {
assert.strictEqual(mimeTypes.contentType('jade'), 'text/jade; charset=utf-8')
})
it('should return content-type for "json"', function () {
assert.strictEqual(mimeTypes.contentType('json'), 'application/json; charset=utf-8')
})
it('should return false for unknown extensions', function () {
assert.strictEqual(mimeTypes.contentType('bogus'), false)
})
it('should return false for invalid arguments', function () {
assert.strictEqual(mimeTypes.contentType({}), false)
assert.strictEqual(mimeTypes.contentType(null), false)
assert.strictEqual(mimeTypes.contentType(true), false)
assert.strictEqual(mimeTypes.contentType(42), false)
})
})
describe('.contentType(type)', function () {
it('should attach charset to "application/json"', function () {
assert.strictEqual(mimeTypes.contentType('application/json'), 'application/json; charset=utf-8')
})
it('should attach charset to "application/json; foo=bar"', function () {
assert.strictEqual(mimeTypes.contentType('application/json; foo=bar'), 'application/json; foo=bar; charset=utf-8')
})
it('should attach charset to "TEXT/HTML"', function () {
assert.strictEqual(mimeTypes.contentType('TEXT/HTML'), 'TEXT/HTML; charset=utf-8')
})
it('should attach charset to "text/html"', function () {
assert.strictEqual(mimeTypes.contentType('text/html'), 'text/html; charset=utf-8')
})
it('should not alter "text/html; charset=iso-8859-1"', function () {
assert.strictEqual(mimeTypes.contentType('text/html; charset=iso-8859-1'), 'text/html; charset=iso-8859-1')
})
it('should return type for unknown types', function () {
assert.strictEqual(mimeTypes.contentType('application/x-bogus'), 'application/x-bogus')
})
})
describe('.extension(type)', function () {
it('should return extension for mime type', function () {
assert.strictEqual(mimeTypes.extension('text/html'), 'html')
assert.strictEqual(mimeTypes.extension(' text/html'), 'html')
assert.strictEqual(mimeTypes.extension('text/html '), 'html')
})
it('should return false for unknown type', function () {
assert.strictEqual(mimeTypes.extension('application/x-bogus'), false)
})
it('should return false for non-type string', function () {
assert.strictEqual(mimeTypes.extension('bogus'), false)
})
it('should return false for non-strings', function () {
assert.strictEqual(mimeTypes.extension(null), false)
assert.strictEqual(mimeTypes.extension(undefined), false)
assert.strictEqual(mimeTypes.extension(42), false)
assert.strictEqual(mimeTypes.extension({}), false)
})
it('should return extension for mime type with parameters', function () {
assert.strictEqual(mimeTypes.extension('text/html;charset=UTF-8'), 'html')
assert.strictEqual(mimeTypes.extension('text/HTML; charset=UTF-8'), 'html')
assert.strictEqual(mimeTypes.extension('text/html; charset=UTF-8'), 'html')
assert.strictEqual(mimeTypes.extension('text/html; charset=UTF-8 '), 'html')
assert.strictEqual(mimeTypes.extension('text/html ; charset=UTF-8'), 'html')
})
})
describe('.lookup(extension)', function () {
it('should return mime type for ".html"', function () {
assert.strictEqual(mimeTypes.lookup('.html'), 'text/html')
})
it('should return mime type for ".js"', function () {
assert.strictEqual(mimeTypes.lookup('.js'), 'text/javascript')
})
it('should return mime type for ".json"', function () {
assert.strictEqual(mimeTypes.lookup('.json'), 'application/json')
})
it('should return mime type for ".rtf"', function () {
assert.strictEqual(mimeTypes.lookup('.rtf'), 'application/rtf')
})
it('should return mime type for ".txt"', function () {
assert.strictEqual(mimeTypes.lookup('.txt'), 'text/plain')
})
it('should return mime type for ".xml"', function () {
assert.strictEqual(mimeTypes.lookup('.xml'), 'application/xml')
})
it('should work without the leading dot', function () {
assert.strictEqual(mimeTypes.lookup('html'), 'text/html')
assert.strictEqual(mimeTypes.lookup('xml'), 'application/xml')
})
it('should be case insensitive', function () {
assert.strictEqual(mimeTypes.lookup('HTML'), 'text/html')
assert.strictEqual(mimeTypes.lookup('.Xml'), 'application/xml')
})
it('should return false for unknown extension', function () {
assert.strictEqual(mimeTypes.lookup('.bogus'), false)
assert.strictEqual(mimeTypes.lookup('bogus'), false)
})
it('should return false for non-strings', function () {
assert.strictEqual(mimeTypes.lookup(null), false)
assert.strictEqual(mimeTypes.lookup(undefined), false)
assert.strictEqual(mimeTypes.lookup(42), false)
assert.strictEqual(mimeTypes.lookup({}), false)
})
})
describe('.lookup(path)', function () {
it('should return mime type for file name', function () {
assert.strictEqual(mimeTypes.lookup('page.html'), 'text/html')
})
it('should return mime type for relative path', function () {
assert.strictEqual(mimeTypes.lookup('path/to/page.html'), 'text/html')
assert.strictEqual(mimeTypes.lookup('path\\to\\page.html'), 'text/html')
})
it('should return mime type for absolute path', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/page.html'), 'text/html')
assert.strictEqual(mimeTypes.lookup('C:\\path\\to\\page.html'), 'text/html')
})
it('should be case insensitive', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/PAGE.HTML'), 'text/html')
assert.strictEqual(mimeTypes.lookup('C:\\path\\to\\PAGE.HTML'), 'text/html')
})
it('should return false for unknown extension', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/file.bogus'), false)
})
it('should return false for path without extension', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/json'), false)
})
describe('path with dotfile', function () {
it('should return false when extension-less', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/.json'), false)
})
it('should return mime type when there is extension', function () {
assert.strictEqual(mimeTypes.lookup('/path/to/.config.json'), 'application/json')
})
it('should return mime type when there is extension, but no path', function () {
assert.strictEqual(mimeTypes.lookup('.config.json'), 'application/json')
})
})
})
})