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