Skip to content

Commit ed23e04

Browse files
committed
test: utf8 check
1 parent 6de8abe commit ed23e04

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

test/fixtures/utf8.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>UTF-8 text</title>
6+
</head>
7+
<body>
8+
你好,世界!
9+
</body>
10+
</html>

test/integration/binary.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,40 @@ describe('node-static (CLI)', function () {
6767
assert.equal(text, 'hello world', 'should respond with hello world');
6868
});
6969

70+
it('serving file within directory with UTF-8 content-type', async function () {
71+
const {response /* , stdout */} =
72+
/**
73+
* @type {{
74+
* response: Response,
75+
* stdout: string
76+
* }}
77+
*/ (await spawnConditional(
78+
binFile,
79+
[
80+
'-p', this.port, fixturePath,
81+
'-H', JSON.stringify({
82+
'Content-Type': 'text/html;charset=UTF-8'
83+
})
84+
],
85+
timeout - 9000,
86+
{
87+
condition: /serving ".*?"/,
88+
action: (/* err, stdout */) => {
89+
return fetch(
90+
`http://localhost:${this.port}/utf8.html`
91+
);
92+
}
93+
}));
94+
95+
const {status} = response;
96+
const contentType = response.headers.get('content-type');
97+
const text = await response.text();
98+
99+
assert.equal(status, 200, 'should respond with 200');
100+
assert.equal(contentType, 'text/html', 'should respond with text/html');
101+
assert.include(text, '你好,世界!', 'should respond with hello world in Chinese');
102+
});
103+
70104
it('serving file within directory with server info', async function () {
71105
const {response /* , stdout */} =
72106
/**

0 commit comments

Comments
 (0)