|
1 | 1 | import test from "ava" |
2 | 2 | import { Headers } from "node-fetch" |
3 | 3 | import { encode } from "iconv-lite" |
4 | | -import convertBody from "./src" |
| 4 | +import convertBody from "./source" |
5 | 5 |
|
6 | | -test("should support encoding decode, xml dtd detect", (t) => { |
| 6 | +test("should support encoding decode, xml dtd detect", t => { |
7 | 7 | const text = "<?xml version=\"1.0\" encoding=\"EUC-JP\"?><title>日本語</title>" |
8 | 8 | t.is(convertBody(encode(text, "EUC-JP"), new Headers({ "Content-Type": "text/xml" })), text) |
9 | 9 | }) |
10 | 10 |
|
11 | | -test("should support encoding decode, content-type detect", (t) => { |
| 11 | +test("should support encoding decode, content-type detect", t => { |
12 | 12 | const text = "<div>日本語</div>" |
13 | 13 | t.is(convertBody(encode(text, "Shift_JIS"), new Headers({ "Content-Type": "text/html; charset=Shift-JIS" })), text) |
14 | 14 | }) |
15 | 15 |
|
16 | | -test("should support encoding decode, html5 detect", (t) => { |
| 16 | +test("should support encoding decode, html5 detect", t => { |
17 | 17 | const text = "<meta charset=\"gbk\"><div>中文</div>" |
18 | 18 | t.is(convertBody(encode(text, "gbk"), new Headers({ "Content-Type": "text/html" })), text) |
19 | 19 | }) |
20 | 20 |
|
21 | | -test("should support encoding decode, html4 detect", (t) => { |
| 21 | +test("should support encoding decode, html4 detect", t => { |
22 | 22 | const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><div>中文</div>" |
23 | 23 | t.is(convertBody(encode(text, "gb2312"), new Headers({ "Content-Type": "text/html" })), text) |
24 | 24 | }) |
25 | 25 |
|
26 | | -test("should default to utf8 encoding", (t) => { |
27 | | - const text = "中文" |
28 | | - t.is(convertBody(text), text) |
29 | | -}) |
30 | | - |
31 | | -test("should support uncommon content-type order, end with qs", (t) => { |
| 26 | +test("should support uncommon content-type order, end with qs", t => { |
32 | 27 | const text = "中文" |
33 | 28 | t.is(convertBody(encode(text, "gbk"), new Headers({ "Content-Type": "text/plain; charset=gbk; qs=1" })), text) |
34 | 29 | }) |
35 | 30 |
|
36 | | -test("should support chunked encoding, html4 detect", (t) => { |
| 31 | +test("should support chunked encoding, html4 detect", t => { |
37 | 32 | const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" /><div>日本語</div>" |
38 | 33 | const padding = "a".repeat(10) |
39 | 34 | t.is(convertBody(encode(padding + text, "Shift_JIS"), new Headers({ "Content-Type": "text/html", "Transfer-Encoding": "chunked" })), padding + text) |
40 | 35 | }) |
41 | 36 |
|
42 | | -test("should only do encoding detection up to 1024 bytes", (t) => { |
| 37 | +test("should only do encoding detection up to 1024 bytes", t => { |
43 | 38 | const text = "中文" |
44 | 39 | const padding = "a".repeat(1200) |
45 | 40 | t.not(convertBody(encode(padding + text, "gbk"), new Headers({ "Content-Type": "text/html", "Transfer-Encoding": "chunked" })), text) |
|
0 commit comments