chromiumly 2.4.0 → 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.
Files changed (66) hide show
  1. package/dist/chromium/converters/converter.js.map +1 -1
  2. package/dist/chromium/converters/html.converter.d.ts +4 -6
  3. package/dist/chromium/converters/html.converter.js +3 -9
  4. package/dist/chromium/converters/html.converter.js.map +1 -1
  5. package/dist/chromium/converters/markdown.converter.d.ts +5 -7
  6. package/dist/chromium/converters/markdown.converter.js +3 -16
  7. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  8. package/dist/chromium/converters/url.converter.d.ts +3 -5
  9. package/dist/chromium/converters/url.converter.js +1 -1
  10. package/dist/chromium/converters/url.converter.js.map +1 -1
  11. package/dist/chromium/index.js.map +1 -1
  12. package/dist/chromium/interfaces/converter.types.d.ts +3 -6
  13. package/dist/chromium/utils/converter.utils.d.ts +3 -1
  14. package/dist/chromium/utils/converter.utils.js +24 -21
  15. package/dist/chromium/utils/converter.utils.js.map +1 -1
  16. package/dist/common/constants.js.map +1 -1
  17. package/dist/common/gotenberg.utils.js.map +1 -1
  18. package/dist/common/index.d.ts +1 -0
  19. package/dist/common/index.js.map +1 -1
  20. package/dist/common/types.d.ts +3 -0
  21. package/dist/common/types.js +3 -0
  22. package/dist/common/types.js.map +1 -0
  23. package/dist/gotenberg.js.map +1 -1
  24. package/dist/libre-office/index.js.map +1 -1
  25. package/dist/libre-office/utils/constants.js.map +1 -1
  26. package/dist/libre-office/utils/libre-office.utils.d.ts +3 -4
  27. package/dist/libre-office/utils/libre-office.utils.js +18 -9
  28. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  29. package/dist/main.config.js.map +1 -1
  30. package/dist/main.js.map +1 -1
  31. package/dist/pdf-engines/index.js.map +1 -1
  32. package/dist/pdf-engines/pdf.engine.js +3 -3
  33. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  34. package/dist/pdf-engines/utils/engine.utils.d.ts +2 -3
  35. package/dist/pdf-engines/utils/engine.utils.js +17 -8
  36. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/chromium/converters/converter.ts +5 -5
  39. package/src/chromium/converters/html.converter.ts +54 -60
  40. package/src/chromium/converters/markdown.converter.ts +56 -68
  41. package/src/chromium/converters/tests/html.converter.test.ts +119 -135
  42. package/src/chromium/converters/tests/markdown.converter.test.ts +131 -150
  43. package/src/chromium/converters/tests/url.converter.test.ts +114 -123
  44. package/src/chromium/converters/url.converter.ts +55 -57
  45. package/src/chromium/index.ts +3 -3
  46. package/src/chromium/interfaces/converter.types.ts +27 -27
  47. package/src/chromium/utils/converter.utils.ts +141 -139
  48. package/src/chromium/utils/tests/converter.utils.test.ts +312 -311
  49. package/src/common/constants.ts +3 -3
  50. package/src/common/gotenberg.utils.ts +16 -16
  51. package/src/common/index.ts +3 -2
  52. package/src/common/tests/gotenberg.utils.test.ts +54 -54
  53. package/src/common/types.ts +3 -0
  54. package/src/gotenberg.ts +4 -4
  55. package/src/libre-office/index.ts +2 -2
  56. package/src/libre-office/interfaces/libre-office.types.ts +2 -2
  57. package/src/libre-office/utils/constants.ts +76 -76
  58. package/src/libre-office/utils/libre-office.utils.ts +42 -35
  59. package/src/libre-office/utils/tests/libre-office.utils.test.ts +81 -69
  60. package/src/main.config.ts +22 -21
  61. package/src/main.ts +3 -3
  62. package/src/pdf-engines/index.ts +1 -1
  63. package/src/pdf-engines/pdf.engine.ts +49 -49
  64. package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
  65. package/src/pdf-engines/utils/engine.utils.ts +20 -12
  66. 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 { createReadStream, promises } from "fs";
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 { PdfFormat } from "../../../common";
8
- import { MarkdownConverter } from "../markdown.converter";
7
+ import {PdfFormat} from "../../../common";
8
+ import {MarkdownConverter} from "../markdown.converter";
9
9
 
10
- const { Response } = jest.requireActual("node-fetch");
10
+ const {Response} = jest.requireActual("node-fetch");
11
11
  jest.mock("node-fetch", () => jest.fn());
12
12
 
13
13
  describe("MarkdownConverter", () => {
14
- const mockPromisesAccess = jest.spyOn(promises, "access");
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("when files exist", () => {
39
- it("should return a buffer", async () => {
40
- mockPromisesAccess.mockResolvedValue();
41
- mockFetch.mockResolvedValue(new Response("content"));
42
- const buffer = await converter.convert({
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("when buffers passed", () => {
51
- it("should return a buffer", async () => {
52
- mockPromisesAccess.mockResolvedValue();
53
- mockFetch.mockResolvedValue(new Response("content"));
54
- const buffer = await converter.convert({
55
- html: Buffer.from("html"),
56
- markdown: Buffer.from("markdown"),
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
- describe("when pdf format parameter is passed", () => {
63
- it("should return a buffer", async () => {
64
- mockPromisesAccess.mockResolvedValue();
65
- mockFetch.mockResolvedValue(new Response("content"));
66
- const buffer = await converter.convert({
67
- html: "path/to/index.html",
68
- markdown: "path/to/file.md",
69
- pdfFormat: PdfFormat.A_2b,
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
- describe("when page properties parameter is passed", () => {
77
- it("should return a buffer", async () => {
78
- mockPromisesAccess.mockResolvedValue();
79
- mockFetch.mockResolvedValue(new Response("content"));
80
- const buffer = await converter.convert({
81
- html: "path/to/index.html",
82
- markdown: "path/to/file.md",
83
- properties: { size: { width: 8.3, height: 11.7 } },
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
- describe("when header parameter is passed", () => {
91
- it("should return a buffer", async () => {
92
- mockPromisesAccess.mockResolvedValue();
93
- mockFetch.mockResolvedValue(new Response("content"));
94
- const buffer = await converter.convert({
95
- html: "path/to/index.html",
96
- markdown: "path/to/file.md",
97
- header: "path/to/header.html",
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
- describe("when footer parameter is passed", () => {
105
- it("should return a buffer", async () => {
106
- mockPromisesAccess.mockResolvedValue();
107
- mockFetch.mockResolvedValue(new Response("content"));
108
- const buffer = await converter.convert({
109
- html: "path/to/index.html",
110
- markdown: "path/to/file.md",
111
- footer: "path/to/footer.html",
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
- describe("when emulatedMediaType parameter is passed", () => {
119
- it("should return a buffer", async () => {
120
- mockPromisesAccess.mockResolvedValue();
121
- mockFetch.mockResolvedValue(new Response("content"));
122
- const buffer = await converter.convert({
123
- html: "path/to/index.html",
124
- markdown: "path/to/file.md",
125
- emulatedMediaType: "screen",
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
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
129
- expect(buffer).toEqual(Buffer.from("content"));
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
- describe("when all parameters are passed", () => {
134
- it("should return a buffer", async () => {
135
- mockPromisesAccess.mockResolvedValue();
136
- mockFetch.mockResolvedValue(new Response("content"));
137
- const buffer = await converter.convert({
138
- html: "path/to/index.html",
139
- markdown: "path/to/file.md",
140
- header: "path/to/header.html",
141
- footer: "path/to/footer.html",
142
- pdfFormat: PdfFormat.A_1a,
143
- emulatedMediaType: "screen",
144
- properties: { size: { width: 8.3, height: 11.7 } },
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
- describe("when file does not exist", () => {
152
- it("should throw an error", async () => {
153
- const errorMessage =
154
- "ENOENT: no such file or directory, access 'path/to/index.html'";
155
- mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
156
-
157
- await expect(() =>
158
- converter.convert({
159
- html: "path/to/index.html",
160
- markdown: "path/to/file.md",
161
- })
162
- ).rejects.toThrow(errorMessage);
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
- describe("when fetch request fails", () => {
167
- it("should throw an error", async () => {
168
- const errorMessage =
169
- "FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
170
- mockPromisesAccess.mockResolvedValue();
171
- mockFetch.mockRejectedValue(new Error(errorMessage));
172
- await expect(() =>
173
- converter.convert({
174
- html: "path/to/index.html",
175
- markdown: "path/to/file.md",
176
- })
177
- ).rejects.toThrow(errorMessage);
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 { createReadStream, promises } from "fs";
2
+ import {createReadStream} from "fs";
3
3
  import FormData from "form-data";
4
4
  import fetch from "node-fetch";
5
5
 
6
- import { PdfFormat } from "../../../common";
7
- import { UrlConverter } from "../url.converter";
6
+ import {PdfFormat} from "../../../common";
7
+ import {UrlConverter} from "../url.converter";
8
8
 
9
- const { Response } = jest.requireActual("node-fetch");
9
+ const {Response} = jest.requireActual("node-fetch");
10
10
  jest.mock("node-fetch", () => jest.fn());
11
11
 
12
12
  describe("HtmlConverter", () => {
13
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
14
- const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
15
- const mockPromisesAccess = jest.spyOn(promises, "access");
16
-
17
- const converter = new UrlConverter();
18
-
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/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("when header parameter is passed", () => {
49
- it("should return a buffer", async () => {
50
- mockFetch.mockResolvedValueOnce(new Response("content"));
51
- mockPromisesAccess.mockResolvedValue();
52
- mockFetch.mockResolvedValue(new Response("content"));
53
- const buffer = await converter.convert({
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
- describe("when footer parameter is passed", () => {
63
- it("should return a buffer", async () => {
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
- describe("when pdf format parameter is passed", () => {
77
- it("should return a buffer", async () => {
78
- mockFetch.mockResolvedValueOnce(new Response("content"));
79
- const buffer = await converter.convert({
80
- url: "http://www.example.com/",
81
- pdfFormat: PdfFormat.A_3b,
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
- describe("when page properties parameter is passed", () => {
89
- it("should return a buffer", async () => {
90
- mockFetch.mockResolvedValueOnce(new Response("content"));
91
- const buffer = await converter.convert({
92
- url: "http://www.example.com/",
93
- properties: { size: { width: 8.3, height: 11.7 } },
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
- describe("when emulatedMediaType parameter is passed", () => {
101
- it("should return a buffer", async () => {
102
- mockPromisesAccess.mockResolvedValue();
103
- mockFetch.mockResolvedValue(new Response("content"));
104
- const buffer = await converter.convert({
105
- url: "http://www.example.com/",
106
- emulatedMediaType: "screen",
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
- describe("when all parameters are passed", () => {
114
- it("should return a buffer", async () => {
115
- mockPromisesAccess.mockResolvedValue();
116
- mockFetch.mockResolvedValue(new Response("content"));
117
- const buffer = await converter.convert({
118
- url: "http://www.example.com/",
119
- header: "path/to/header.html",
120
- footer: "path/to/footer.html",
121
- pdfFormat: PdfFormat.A_1a,
122
- emulatedMediaType: "screen",
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
- describe("when URL is invalid", () => {
131
- it("should throw an error", async () => {
132
- await expect(() =>
133
- converter.convert({ url: "invalid url" })
134
- ).rejects.toThrow("Invalid URL");
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
- describe("when fetch request fails", () => {
139
- it("should throw an error", async () => {
140
- const errorMessage =
141
- "FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
142
- mockFetch.mockRejectedValueOnce(new Error(errorMessage));
143
- await expect(() =>
144
- converter.convert({ url: "http://www.example.com/" })
145
- ).rejects.toThrow(errorMessage);
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
  });