-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathcontent-type.test.js
76 lines (58 loc) · 1.56 KB
/
content-type.test.js
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
'use strict';
const test = require('tap').test;
const http = require('http');
const ecstatic = require('../lib/core');
const checkHeaders = require('./check-headers.js');
const root = `${__dirname}/public/`;
test('global default contentType', (t) => {
let server = null;
try {
server = http.createServer(ecstatic({
root,
contentType: 'text/plain',
}));
} catch (e) {
t.fail(e.message);
t.end();
}
t.plan(3);
checkHeaders(t, server, 'f_f', (t, headers) => {
t.equal(headers['content-type'], 'text/plain; charset=UTF-8');
});
});
test('content type text', (t) => {
t.plan(3);
const server = http.createServer(
ecstatic({root})
);
checkHeaders(t, server, 'subdir/e.html', (t, headers) => {
t.equal(headers['content-type'], 'text/html; charset=UTF-8');
});
});
test('content type binary', (t) => {
t.plan(3);
const server = http.createServer(
ecstatic({root})
);
checkHeaders(t, server, 'subdir/app.wasm', (t, headers) => {
t.equal(headers['content-type'], 'application/wasm');
});
});
test('charset arabic', (t) => {
t.plan(3);
const server = http.createServer(
ecstatic({root})
);
checkHeaders(t, server, 'charset/arabic.html', (t, headers) => {
t.equal(headers['content-type'], 'text/html; charset=ISO-8859-6');
});
});
test('charset Shift_JIS', (t) => {
t.plan(3);
const server = http.createServer(
ecstatic({root})
);
checkHeaders(t, server, 'charset/shift_jis.html', (t, headers) => {
t.equal(headers['content-type'], 'text/html; charset=Shift_JIS');
});
});