chromiumly 2.4.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -40
- package/dist/chromium/converters/converter.d.ts +13 -0
- package/dist/chromium/converters/converter.js +10 -0
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +32 -6
- package/dist/chromium/converters/html.converter.js +30 -9
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +34 -7
- package/dist/chromium/converters/markdown.converter.js +32 -16
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +31 -5
- package/dist/chromium/converters/url.converter.js +29 -1
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/converter.types.d.ts +3 -6
- package/dist/chromium/utils/converter.utils.d.ts +27 -1
- package/dist/chromium/utils/converter.utils.js +48 -21
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/gotenberg.utils.d.ts +18 -0
- package/dist/common/gotenberg.utils.js +18 -0
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +3 -0
- package/dist/common/types.js +3 -0
- package/dist/common/types.js.map +1 -0
- package/dist/gotenberg.d.ts +8 -0
- package/dist/gotenberg.js +8 -0
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js +76 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +19 -4
- package/dist/libre-office/utils/libre-office.utils.js +39 -7
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +43 -0
- package/dist/main.config.js +43 -0
- package/dist/main.config.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +31 -5
- package/dist/pdf-engines/pdf.engine.js +31 -3
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +12 -3
- package/dist/pdf-engines/utils/engine.utils.js +27 -8
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +8 -7
- package/src/chromium/converters/converter.ts +18 -5
- package/src/chromium/converters/html.converter.ts +82 -61
- package/src/chromium/converters/markdown.converter.ts +86 -69
- package/src/chromium/converters/tests/html.converter.test.ts +119 -135
- package/src/chromium/converters/tests/markdown.converter.test.ts +131 -150
- package/src/chromium/converters/tests/url.converter.test.ts +114 -123
- package/src/chromium/converters/url.converter.ts +84 -60
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/converter.types.ts +27 -27
- package/src/chromium/utils/converter.utils.ts +165 -139
- package/src/chromium/utils/tests/converter.utils.test.ts +312 -311
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +36 -17
- package/src/common/index.ts +3 -2
- package/src/common/tests/gotenberg.utils.test.ts +54 -54
- package/src/common/types.ts +3 -0
- package/src/gotenberg.ts +13 -4
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/interfaces/libre-office.types.ts +2 -2
- package/src/libre-office/utils/constants.ts +76 -76
- package/src/libre-office/utils/libre-office.utils.ts +72 -37
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +100 -68
- package/src/main.config.ts +68 -22
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +77 -49
- package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
- package/src/pdf-engines/utils/engine.utils.ts +30 -12
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
|
@@ -1,181 +1,162 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import {
|
|
2
|
+
import {createReadStream, promises} from "fs";
|
|
3
3
|
|
|
4
4
|
import FormData from "form-data";
|
|
5
5
|
import fetch from "node-fetch";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import {PdfFormat} from "../../../common";
|
|
8
|
+
import {MarkdownConverter} from "../markdown.converter";
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const {Response} = jest.requireActual("node-fetch");
|
|
11
11
|
jest.mock("node-fetch", () => jest.fn());
|
|
12
12
|
|
|
13
13
|
describe("MarkdownConverter", () => {
|
|
14
|
-
|
|
15
|
-
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
16
|
-
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
17
|
-
|
|
18
|
-
const converter = new MarkdownConverter();
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
jest.resetAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("endpoint", () => {
|
|
24
|
-
it("should route to Chromium Markdown route", () => {
|
|
25
|
-
expect(converter.endpoint).toEqual(
|
|
26
|
-
"http://localhost:3000/forms/chromium/convert/markdown"
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("convert", () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
(createReadStream as jest.Mock) = jest
|
|
34
|
-
.fn()
|
|
35
|
-
.mockImplementation((file) => file);
|
|
36
|
-
});
|
|
14
|
+
const converter = new MarkdownConverter();
|
|
37
15
|
|
|
38
|
-
describe("
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
html: "path/to/index.html",
|
|
44
|
-
markdown: "path/to/file.md",
|
|
16
|
+
describe("endpoint", () => {
|
|
17
|
+
it("should route to Chromium Markdown route", () => {
|
|
18
|
+
expect(converter.endpoint).toEqual(
|
|
19
|
+
"http://localhost:3000/forms/chromium/convert/markdown"
|
|
20
|
+
);
|
|
45
21
|
});
|
|
46
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
47
|
-
});
|
|
48
22
|
});
|
|
49
23
|
|
|
50
|
-
describe("
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
24
|
+
describe("convert", () => {
|
|
25
|
+
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
26
|
+
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
27
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
(createReadStream as jest.Mock) = jest.fn()
|
|
57
31
|
});
|
|
58
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
32
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.resetAllMocks();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("when html and markdown parameters are passed", () => {
|
|
38
|
+
it("should return a buffer", async () => {
|
|
39
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
40
|
+
const buffer = await converter.convert({
|
|
41
|
+
html: Buffer.from("data"),
|
|
42
|
+
markdown: Buffer.from("markdown"),
|
|
43
|
+
});
|
|
44
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
45
|
+
});
|
|
70
46
|
});
|
|
71
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
72
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
47
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
48
|
+
|
|
49
|
+
describe("when pdf format parameter is passed", () => {
|
|
50
|
+
it("should return a buffer", async () => {
|
|
51
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
52
|
+
const buffer = await converter.convert({
|
|
53
|
+
html: Buffer.from("data"),
|
|
54
|
+
markdown: Buffer.from("markdown"),
|
|
55
|
+
pdfFormat: PdfFormat.A_2b,
|
|
56
|
+
});
|
|
57
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
58
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
59
|
+
});
|
|
84
60
|
});
|
|
85
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
|
|
86
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
62
|
+
describe("when page properties parameter is passed", () => {
|
|
63
|
+
it("should return a buffer", async () => {
|
|
64
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
65
|
+
const buffer = await converter.convert({
|
|
66
|
+
html: Buffer.from("data"),
|
|
67
|
+
markdown: Buffer.from("markdown"),
|
|
68
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
69
|
+
});
|
|
70
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
|
|
71
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
72
|
+
});
|
|
98
73
|
});
|
|
99
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
100
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
74
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
75
|
+
describe("when header parameter is passed", () => {
|
|
76
|
+
it("should return a buffer", async () => {
|
|
77
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
78
|
+
const buffer = await converter.convert({
|
|
79
|
+
html: Buffer.from("data"),
|
|
80
|
+
markdown: Buffer.from("markdown"),
|
|
81
|
+
header: Buffer.from("header"),
|
|
82
|
+
});
|
|
83
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
84
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
85
|
+
});
|
|
112
86
|
});
|
|
113
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
114
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
87
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
88
|
+
describe("when footer parameter is passed", () => {
|
|
89
|
+
it("should return a buffer", async () => {
|
|
90
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
91
|
+
const buffer = await converter.convert({
|
|
92
|
+
html: Buffer.from("data"),
|
|
93
|
+
markdown: Buffer.from("markdown"),
|
|
94
|
+
footer: Buffer.from("footer"),
|
|
95
|
+
});
|
|
96
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
97
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
98
|
+
});
|
|
126
99
|
});
|
|
127
100
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
101
|
+
describe("when emulatedMediaType parameter is passed", () => {
|
|
102
|
+
it("should return a buffer", async () => {
|
|
103
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
104
|
+
const buffer = await converter.convert({
|
|
105
|
+
html: Buffer.from("data"),
|
|
106
|
+
markdown: Buffer.from("markdown"),
|
|
107
|
+
emulatedMediaType: "screen",
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
111
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
132
114
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
115
|
+
describe("when all parameters are passed", () => {
|
|
116
|
+
it("should return a buffer", async () => {
|
|
117
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
118
|
+
const buffer = await converter.convert({
|
|
119
|
+
html: Buffer.from("data"),
|
|
120
|
+
markdown: Buffer.from("markdown"),
|
|
121
|
+
header: Buffer.from("header"),
|
|
122
|
+
footer: Buffer.from("footer"),
|
|
123
|
+
pdfFormat: PdfFormat.A_1a,
|
|
124
|
+
emulatedMediaType: "screen",
|
|
125
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
126
|
+
});
|
|
127
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(8);
|
|
128
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
129
|
+
});
|
|
145
130
|
});
|
|
146
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(8);
|
|
147
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
131
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
132
|
+
describe("when file does not exist", () => {
|
|
133
|
+
it("should throw an error", async () => {
|
|
134
|
+
const errorMessage =
|
|
135
|
+
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
136
|
+
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
137
|
+
|
|
138
|
+
await expect(() =>
|
|
139
|
+
converter.convert({
|
|
140
|
+
html: "path/to/index.html",
|
|
141
|
+
markdown: "path/to/file.md",
|
|
142
|
+
})
|
|
143
|
+
).rejects.toThrow(errorMessage);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
165
146
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
147
|
+
describe("when fetch request fails", () => {
|
|
148
|
+
it("should throw an error", async () => {
|
|
149
|
+
const errorMessage =
|
|
150
|
+
"FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
|
|
151
|
+
mockPromisesAccess.mockResolvedValue();
|
|
152
|
+
mockFetch.mockRejectedValue(new Error(errorMessage));
|
|
153
|
+
await expect(() =>
|
|
154
|
+
converter.convert({
|
|
155
|
+
html: "path/to/index.html",
|
|
156
|
+
markdown: "path/to/file.md",
|
|
157
|
+
})
|
|
158
|
+
).rejects.toThrow(errorMessage);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
179
161
|
});
|
|
180
|
-
});
|
|
181
162
|
});
|
|
@@ -1,149 +1,140 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import {
|
|
2
|
+
import {createReadStream} from "fs";
|
|
3
3
|
import FormData from "form-data";
|
|
4
4
|
import fetch from "node-fetch";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import {PdfFormat} from "../../../common";
|
|
7
|
+
import {UrlConverter} from "../url.converter";
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {Response} = jest.requireActual("node-fetch");
|
|
10
10
|
jest.mock("node-fetch", () => jest.fn());
|
|
11
11
|
|
|
12
12
|
describe("HtmlConverter", () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(createReadStream as jest.Mock) = jest
|
|
21
|
-
.fn()
|
|
22
|
-
.mockImplementation((file) => file);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
jest.resetAllMocks();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("endpoint", () => {
|
|
30
|
-
it("should route to Chromium HTML route", () => {
|
|
31
|
-
expect(converter.endpoint).toEqual(
|
|
32
|
-
"http://localhost:3000/forms/chromium/convert/url"
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("convert", () => {
|
|
38
|
-
describe("when URL is valid", () => {
|
|
39
|
-
it("should return a buffer", async () => {
|
|
40
|
-
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
41
|
-
const buffer = await converter.convert({
|
|
42
|
-
url: "http://www.example.com/",
|
|
13
|
+
const converter = new UrlConverter();
|
|
14
|
+
|
|
15
|
+
describe("endpoint", () => {
|
|
16
|
+
it("should route to Chromium HTML route", () => {
|
|
17
|
+
expect(converter.endpoint).toEqual(
|
|
18
|
+
"http://localhost:3000/forms/chromium/convert/url"
|
|
19
|
+
);
|
|
43
20
|
});
|
|
44
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
45
|
-
});
|
|
46
21
|
});
|
|
47
22
|
|
|
48
|
-
describe("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
url: "http://www.example.com/",
|
|
55
|
-
header: "path/to/header.html",
|
|
23
|
+
describe("convert", () => {
|
|
24
|
+
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
25
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
(createReadStream as jest.Mock) = jest.fn()
|
|
56
29
|
});
|
|
57
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
58
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
65
|
-
mockPromisesAccess.mockResolvedValue();
|
|
66
|
-
mockFetch.mockResolvedValue(new Response("content"));
|
|
67
|
-
const buffer = await converter.convert({
|
|
68
|
-
url: "http://www.example.com/",
|
|
69
|
-
footer: "path/to/footer.html",
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
jest.resetAllMocks();
|
|
70
33
|
});
|
|
71
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
72
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
34
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
describe("when URL is valid", () => {
|
|
36
|
+
it("should return a buffer", async () => {
|
|
37
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
38
|
+
const buffer = await converter.convert({
|
|
39
|
+
url: "http://www.example.com/",
|
|
40
|
+
});
|
|
41
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
42
|
+
});
|
|
82
43
|
});
|
|
83
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
84
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
44
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
45
|
+
describe("when header parameter is passed", () => {
|
|
46
|
+
it("should return a buffer", async () => {
|
|
47
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
48
|
+
const buffer = await converter.convert({
|
|
49
|
+
url: "http://www.example.com/",
|
|
50
|
+
header: Buffer.from("header"),
|
|
51
|
+
});
|
|
52
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
53
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
54
|
+
});
|
|
94
55
|
});
|
|
95
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
96
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
56
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
57
|
+
describe("when footer parameter is passed", () => {
|
|
58
|
+
it("should return a buffer", async () => {
|
|
59
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
60
|
+
const buffer = await converter.convert({
|
|
61
|
+
url: "http://www.example.com/",
|
|
62
|
+
footer: Buffer.from("footer"),
|
|
63
|
+
});
|
|
64
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
65
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
66
|
+
});
|
|
107
67
|
});
|
|
108
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
109
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
68
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
properties: { size: { width: 8.3, height: 11.7 } },
|
|
69
|
+
describe("when pdf format parameter is passed", () => {
|
|
70
|
+
it("should return a buffer", async () => {
|
|
71
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
72
|
+
const buffer = await converter.convert({
|
|
73
|
+
url: "http://www.example.com/",
|
|
74
|
+
pdfFormat: PdfFormat.A_3b,
|
|
75
|
+
});
|
|
76
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
77
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
78
|
+
});
|
|
124
79
|
});
|
|
125
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
|
|
126
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
80
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
81
|
+
describe("when page properties parameter is passed", () => {
|
|
82
|
+
it("should return a buffer", async () => {
|
|
83
|
+
mockFetch.mockResolvedValueOnce(new Response("content"));
|
|
84
|
+
const buffer = await converter.convert({
|
|
85
|
+
url: "http://www.example.com/",
|
|
86
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
87
|
+
});
|
|
88
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
89
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
90
|
+
});
|
|
91
|
+
});
|
|
137
92
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
93
|
+
describe("when emulatedMediaType parameter is passed", () => {
|
|
94
|
+
it("should return a buffer", async () => {
|
|
95
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
96
|
+
const buffer = await converter.convert({
|
|
97
|
+
url: "http://www.example.com/",
|
|
98
|
+
emulatedMediaType: "screen",
|
|
99
|
+
});
|
|
100
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
101
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("when all parameters are passed", () => {
|
|
106
|
+
it("should return a buffer", async () => {
|
|
107
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
108
|
+
const buffer = await converter.convert({
|
|
109
|
+
url: "http://www.example.com/",
|
|
110
|
+
header: Buffer.from("header"),
|
|
111
|
+
footer: Buffer.from("footer"),
|
|
112
|
+
pdfFormat: PdfFormat.A_1a,
|
|
113
|
+
emulatedMediaType: "screen",
|
|
114
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
115
|
+
});
|
|
116
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
|
|
117
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("when URL is invalid", () => {
|
|
122
|
+
it("should throw an error", async () => {
|
|
123
|
+
await expect(() =>
|
|
124
|
+
converter.convert({url: "invalid url"})
|
|
125
|
+
).rejects.toThrow("Invalid URL");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("when fetch request fails", () => {
|
|
130
|
+
it("should throw an error", async () => {
|
|
131
|
+
const errorMessage =
|
|
132
|
+
"FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
|
|
133
|
+
mockFetch.mockRejectedValueOnce(new Error(errorMessage));
|
|
134
|
+
await expect(() =>
|
|
135
|
+
converter.convert({url: "http://www.example.com/"})
|
|
136
|
+
).rejects.toThrow(errorMessage);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
147
139
|
});
|
|
148
|
-
});
|
|
149
140
|
});
|