chromiumly 2.3.1 → 2.5.0
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/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +4 -6
- package/dist/chromium/converters/html.converter.js +3 -4
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +5 -7
- package/dist/chromium/converters/markdown.converter.js +3 -6
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +3 -5
- package/dist/chromium/converters/url.converter.js +1 -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 -5
- package/dist/chromium/utils/converter.utils.d.ts +3 -1
- package/dist/chromium/utils/converter.utils.js +26 -11
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/constants.js.map +1 -1
- 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.js.map +1 -1
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +3 -4
- package/dist/libre-office/utils/libre-office.utils.js +18 -9
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- 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.js +3 -3
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +2 -3
- package/dist/pdf-engines/utils/engine.utils.js +17 -8
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +7 -7
- package/src/chromium/converters/converter.ts +5 -5
- package/src/chromium/converters/html.converter.ts +54 -56
- package/src/chromium/converters/markdown.converter.ts +57 -60
- package/src/chromium/converters/tests/html.converter.test.ts +121 -126
- package/src/chromium/converters/tests/markdown.converter.test.ts +132 -139
- package/src/chromium/converters/tests/url.converter.test.ts +114 -123
- package/src/chromium/converters/url.converter.ts +55 -57
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/converter.types.ts +27 -27
- package/src/chromium/utils/converter.utils.ts +141 -129
- package/src/chromium/utils/tests/converter.utils.test.ts +315 -280
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +16 -16
- 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 +4 -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 +42 -35
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +81 -69
- package/src/main.config.ts +22 -21
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +49 -49
- package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
- package/src/pdf-engines/utils/engine.utils.ts +20 -12
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
|
@@ -1,67 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
2
|
import FormData from "form-data";
|
|
4
3
|
|
|
5
|
-
import {
|
|
4
|
+
import {GotenbergUtils, PathLikeOrReadStream, PdfFormat} from "../../common";
|
|
6
5
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
EmulatedMediaType,
|
|
7
|
+
PageProperties,
|
|
9
8
|
} from "../interfaces/converter.types";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import {ConverterUtils} from "../utils/converter.utils";
|
|
10
|
+
import {Converter} from "./converter";
|
|
11
|
+
import {ChromiumRoute} from "../../main.config";
|
|
13
12
|
|
|
14
13
|
export class HtmlConverter extends Converter {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
constructor() {
|
|
15
|
+
super(ChromiumRoute.HTML);
|
|
16
|
+
}
|
|
18
17
|
|
|
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
|
-
const data = new FormData();
|
|
18
|
+
async convert({
|
|
19
|
+
html,
|
|
20
|
+
header,
|
|
21
|
+
footer,
|
|
22
|
+
properties,
|
|
23
|
+
pdfFormat,
|
|
24
|
+
pdfUA,
|
|
25
|
+
emulatedMediaType,
|
|
26
|
+
waitDelay,
|
|
27
|
+
waitForExpression,
|
|
28
|
+
userAgent,
|
|
29
|
+
extraHttpHeaders,
|
|
30
|
+
failOnConsoleExceptions,
|
|
31
|
+
}: {
|
|
32
|
+
html: PathLikeOrReadStream;
|
|
33
|
+
header?: PathLikeOrReadStream;
|
|
34
|
+
footer?: PathLikeOrReadStream;
|
|
35
|
+
properties?: PageProperties;
|
|
36
|
+
pdfFormat?: PdfFormat;
|
|
37
|
+
pdfUA?: boolean;
|
|
38
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
39
|
+
waitDelay?: string;
|
|
40
|
+
waitForExpression?: string;
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
extraHttpHeaders?: Record<string, string>;
|
|
43
|
+
failOnConsoleExceptions?: boolean;
|
|
44
|
+
}): Promise<Buffer> {
|
|
45
|
+
const data = new FormData();
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
await ConverterUtils.addFile(data, html, "index.html")
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
await ConverterUtils.customize(data, {
|
|
50
|
+
header,
|
|
51
|
+
footer,
|
|
52
|
+
properties,
|
|
53
|
+
pdfFormat,
|
|
54
|
+
pdfUA,
|
|
55
|
+
emulatedMediaType,
|
|
56
|
+
waitDelay,
|
|
57
|
+
waitForExpression,
|
|
58
|
+
userAgent,
|
|
59
|
+
extraHttpHeaders,
|
|
60
|
+
failOnConsoleExceptions,
|
|
61
|
+
});
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
64
|
+
}
|
|
67
65
|
}
|
|
@@ -1,71 +1,68 @@
|
|
|
1
|
-
import { constants, createReadStream, PathLike, promises } from "fs";
|
|
2
|
-
|
|
3
1
|
import FormData from "form-data";
|
|
4
2
|
|
|
5
|
-
import {
|
|
3
|
+
import {GotenbergUtils, PdfFormat, PathLikeOrReadStream} from "../../common";
|
|
6
4
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
EmulatedMediaType,
|
|
6
|
+
PageProperties,
|
|
9
7
|
} from "../interfaces/converter.types";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import {ConverterUtils} from "../utils/converter.utils";
|
|
9
|
+
import {Converter} from "./converter";
|
|
10
|
+
import {ChromiumRoute} from "../../main.config";
|
|
13
11
|
|
|
14
12
|
export class MarkdownConverter extends Converter {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
super(ChromiumRoute.MARKDOWN);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async convert({
|
|
18
|
+
html,
|
|
19
|
+
markdown,
|
|
20
|
+
header,
|
|
21
|
+
footer,
|
|
22
|
+
properties,
|
|
23
|
+
pdfFormat,
|
|
24
|
+
pdfUA,
|
|
25
|
+
emulatedMediaType,
|
|
26
|
+
waitDelay,
|
|
27
|
+
waitForExpression,
|
|
28
|
+
userAgent,
|
|
29
|
+
extraHttpHeaders,
|
|
30
|
+
failOnConsoleExceptions,
|
|
31
|
+
}: {
|
|
32
|
+
html: PathLikeOrReadStream;
|
|
33
|
+
markdown: PathLikeOrReadStream;
|
|
34
|
+
header?: PathLikeOrReadStream;
|
|
35
|
+
footer?: PathLikeOrReadStream;
|
|
36
|
+
properties?: PageProperties;
|
|
37
|
+
pdfFormat?: PdfFormat;
|
|
38
|
+
pdfUA?: boolean;
|
|
39
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
40
|
+
waitDelay?: string;
|
|
41
|
+
waitForExpression?: string;
|
|
42
|
+
userAgent?: string;
|
|
43
|
+
extraHttpHeaders?: Record<string, string>;
|
|
44
|
+
failOnConsoleExceptions?: boolean;
|
|
45
|
+
}): Promise<Buffer> {
|
|
46
|
+
const data = new FormData();
|
|
18
47
|
|
|
19
|
-
|
|
20
|
-
html,
|
|
21
|
-
markdown,
|
|
22
|
-
header,
|
|
23
|
-
footer,
|
|
24
|
-
properties,
|
|
25
|
-
pdfFormat,
|
|
26
|
-
pdfUA,
|
|
27
|
-
emulatedMediaType,
|
|
28
|
-
waitDelay,
|
|
29
|
-
waitForExpression,
|
|
30
|
-
userAgent,
|
|
31
|
-
extraHttpHeaders,
|
|
32
|
-
failOnConsoleExceptions,
|
|
33
|
-
}: {
|
|
34
|
-
html: PathLike;
|
|
35
|
-
markdown: PathLike;
|
|
36
|
-
header?: PathLike;
|
|
37
|
-
footer?: PathLike;
|
|
38
|
-
properties?: PageProperties;
|
|
39
|
-
pdfFormat?: PdfFormat;
|
|
40
|
-
pdfUA?: boolean;
|
|
41
|
-
emulatedMediaType?: EmulatedMediaType;
|
|
42
|
-
waitDelay?: string;
|
|
43
|
-
waitForExpression?: string;
|
|
44
|
-
userAgent?: string;
|
|
45
|
-
extraHttpHeaders?: Record<string, string>;
|
|
46
|
-
failOnConsoleExceptions?: boolean;
|
|
47
|
-
}): Promise<Buffer> {
|
|
48
|
-
await promises.access(html, constants.R_OK);
|
|
49
|
-
await promises.access(markdown, constants.R_OK);
|
|
50
|
-
const data = new FormData();
|
|
48
|
+
await ConverterUtils.addFile(data, html, "index.html");
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
data.append("file.md", createReadStream(markdown));
|
|
50
|
+
await ConverterUtils.addFile(data, markdown, "file.md");
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
await ConverterUtils.customize(data, {
|
|
53
|
+
header,
|
|
54
|
+
footer,
|
|
55
|
+
properties,
|
|
56
|
+
pdfFormat,
|
|
57
|
+
pdfUA,
|
|
58
|
+
emulatedMediaType,
|
|
59
|
+
waitDelay,
|
|
60
|
+
waitForExpression,
|
|
61
|
+
userAgent,
|
|
62
|
+
extraHttpHeaders,
|
|
63
|
+
failOnConsoleExceptions,
|
|
64
|
+
});
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
67
|
+
}
|
|
71
68
|
}
|
|
@@ -1,152 +1,147 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import {
|
|
2
|
+
import {createReadStream, promises} from "fs";
|
|
3
3
|
|
|
4
4
|
import fetch from "node-fetch";
|
|
5
5
|
import FormData from "form-data";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import {PdfFormat} from "../../../common";
|
|
8
|
+
import {HtmlConverter} from "../html.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("HtmlConverter", () => {
|
|
14
|
-
|
|
15
|
-
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
16
|
-
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
17
|
-
|
|
18
|
-
const converter = new HtmlConverter();
|
|
19
|
-
beforeEach(() => {
|
|
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/html"
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("convert", () => {
|
|
38
|
-
describe("when file exists", () => {
|
|
39
|
-
it("should return a buffer", async () => {
|
|
40
|
-
mockPromisesAccess.mockResolvedValue();
|
|
41
|
-
mockFetch.mockResolvedValue(new Response("content"));
|
|
42
|
-
const buffer = await converter.convert({ html: "path/to/index.html" });
|
|
43
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
44
|
-
});
|
|
45
|
-
});
|
|
14
|
+
const converter = new HtmlConverter();
|
|
46
15
|
|
|
47
|
-
describe("
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
html: "path/to/index.html",
|
|
53
|
-
pdfFormat: PdfFormat.A_1a,
|
|
16
|
+
describe("endpoint", () => {
|
|
17
|
+
it("should route to Chromium HTML route", () => {
|
|
18
|
+
expect(converter.endpoint).toEqual(
|
|
19
|
+
"http://localhost:3000/forms/chromium/convert/html"
|
|
20
|
+
);
|
|
54
21
|
});
|
|
55
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
56
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
57
|
-
});
|
|
58
22
|
});
|
|
59
23
|
|
|
60
|
-
describe("
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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()
|
|
67
31
|
});
|
|
68
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
69
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
32
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
mockPromisesAccess.mockResolvedValue();
|
|
76
|
-
mockFetch.mockResolvedValue(new Response("content"));
|
|
77
|
-
const buffer = await converter.convert({
|
|
78
|
-
html: "path/to/index.html",
|
|
79
|
-
header: "path/to/header.html",
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.resetAllMocks();
|
|
80
35
|
});
|
|
81
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
82
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
36
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
37
|
+
describe("when html parameter is 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
|
+
});
|
|
43
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
44
|
+
});
|
|
93
45
|
});
|
|
94
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
95
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
46
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
47
|
+
describe("when pdf format parameter is passed", () => {
|
|
48
|
+
it("should return a buffer", async () => {
|
|
49
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
50
|
+
const buffer = await converter.convert({
|
|
51
|
+
html: Buffer.from("data"),
|
|
52
|
+
pdfFormat: PdfFormat.A_1a,
|
|
53
|
+
});
|
|
54
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
55
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
56
|
+
});
|
|
106
57
|
});
|
|
107
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
108
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
58
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
properties: { size: { width: 8.3, height: 11.7 } },
|
|
59
|
+
describe("when page properties parameter is passed", () => {
|
|
60
|
+
it("should return a buffer", async () => {
|
|
61
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
62
|
+
const buffer = await converter.convert({
|
|
63
|
+
html: Buffer.from("data"),
|
|
64
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
65
|
+
});
|
|
66
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
67
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
68
|
+
});
|
|
123
69
|
});
|
|
124
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
|
|
125
|
-
expect(buffer).toEqual(Buffer.from("content"));
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
70
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
71
|
+
describe("when header parameter is passed", () => {
|
|
72
|
+
it("should return a buffer", async () => {
|
|
73
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
74
|
+
const buffer = await converter.convert({
|
|
75
|
+
html: Buffer.from("data"),
|
|
76
|
+
header: Buffer.from("header"),
|
|
77
|
+
});
|
|
78
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
79
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
80
|
+
});
|
|
81
|
+
});
|
|
139
82
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
83
|
+
describe("when footer parameter is passed", () => {
|
|
84
|
+
it("should return a buffer", async () => {
|
|
85
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
86
|
+
const buffer = await converter.convert({
|
|
87
|
+
html: Buffer.from("data"),
|
|
88
|
+
footer: Buffer.from("footer"),
|
|
89
|
+
});
|
|
90
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
91
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("when emulatedMediaType parameter is passed", () => {
|
|
96
|
+
it("should return a buffer", async () => {
|
|
97
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
98
|
+
const buffer = await converter.convert({
|
|
99
|
+
html: Buffer.from("data"),
|
|
100
|
+
emulatedMediaType: "screen",
|
|
101
|
+
});
|
|
102
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
103
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("when all parameters are passed", () => {
|
|
108
|
+
it("should return a buffer", async () => {
|
|
109
|
+
mockPromisesAccess.mockResolvedValue();
|
|
110
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
111
|
+
const buffer = await converter.convert({
|
|
112
|
+
html: Buffer.from("data"),
|
|
113
|
+
header: Buffer.from("header"),
|
|
114
|
+
footer: Buffer.from("footer"),
|
|
115
|
+
pdfFormat: PdfFormat.A_1a,
|
|
116
|
+
emulatedMediaType: "screen",
|
|
117
|
+
properties: {size: {width: 8.3, height: 11.7}},
|
|
118
|
+
});
|
|
119
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
|
|
120
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("when file does not exist", () => {
|
|
125
|
+
it("should throw an error", async () => {
|
|
126
|
+
const errorMessage =
|
|
127
|
+
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
128
|
+
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
129
|
+
await expect(() =>
|
|
130
|
+
converter.convert({html: "path/to/index.html"})
|
|
131
|
+
).rejects.toThrow(errorMessage);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("when fetch request fails", () => {
|
|
136
|
+
it("should throw an error", async () => {
|
|
137
|
+
const errorMessage =
|
|
138
|
+
"FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
|
|
139
|
+
mockPromisesAccess.mockResolvedValue();
|
|
140
|
+
mockFetch.mockRejectedValue(new Error(errorMessage));
|
|
141
|
+
await expect(() =>
|
|
142
|
+
converter.convert({html: "path/to/index.html"})
|
|
143
|
+
).rejects.toThrow(errorMessage);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
150
146
|
});
|
|
151
|
-
});
|
|
152
147
|
});
|