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.
- package/README.md +55 -35
- package/dist/chromium/converters/converter.d.ts +1 -1
- package/dist/chromium/converters/converter.js +1 -1
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +13 -4
- package/dist/chromium/converters/html.converter.js +9 -2
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +9 -4
- package/dist/chromium/converters/markdown.converter.js +7 -3
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +9 -4
- package/dist/chromium/converters/url.converter.js +6 -2
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.d.ts +3 -3
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/common.types.d.ts +13 -0
- package/dist/chromium/interfaces/common.types.js +3 -0
- package/dist/chromium/interfaces/common.types.js.map +1 -0
- package/dist/chromium/interfaces/converter.types.d.ts +4 -10
- package/dist/chromium/utils/converter.utils.d.ts +2 -12
- package/dist/chromium/utils/converter.utils.js +36 -50
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/gotenberg.utils.d.ts +11 -1
- package/dist/common/gotenberg.utils.js +25 -2
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +3 -3
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/gotenberg.js +4 -3
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.d.ts +2 -2
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js +80 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +3 -3
- package/dist/libre-office/utils/libre-office.utils.js +5 -5
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +1 -1
- package/dist/main.config.js +6 -6
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +3 -3
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.d.ts +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +3 -3
- package/dist/pdf-engines/pdf.engine.js +5 -5
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +2 -2
- package/dist/pdf-engines/utils/engine.utils.js +3 -3
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +25 -17
- package/src/.prettierrc.yml +4 -0
- package/src/chromium/converters/converter.ts +2 -2
- package/src/chromium/converters/html.converter.ts +40 -24
- package/src/chromium/converters/markdown.converter.ts +32 -26
- package/src/chromium/converters/tests/html.converter.test.ts +111 -68
- package/src/chromium/converters/tests/markdown.converter.test.ts +102 -77
- package/src/chromium/converters/tests/url.converter.test.ts +90 -66
- package/src/chromium/converters/url.converter.ts +31 -25
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/common.types.ts +15 -0
- package/src/chromium/interfaces/converter.types.ts +4 -12
- package/src/chromium/utils/converter.utils.ts +67 -60
- package/src/chromium/utils/tests/converter.utils.test.ts +237 -167
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +39 -8
- package/src/common/index.ts +3 -3
- package/src/common/tests/gotenberg.utils.test.ts +38 -31
- package/src/common/types.ts +2 -2
- package/src/gotenberg.ts +9 -9
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/utils/constants.ts +80 -76
- package/src/libre-office/utils/libre-office.utils.ts +21 -18
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +58 -49
- package/src/main.config.ts +13 -13
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +23 -19
- package/src/pdf-engines/tests/pdf.engine.test.ts +52 -49
- package/src/pdf-engines/utils/engine.utils.ts +12 -9
- 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
|
|
2
|
+
import { createReadStream, promises } from 'fs';
|
|
3
3
|
|
|
4
|
-
import fetch from
|
|
5
|
-
import FormData from
|
|
4
|
+
import fetch from 'node-fetch';
|
|
5
|
+
import FormData from 'form-data';
|
|
6
6
|
|
|
7
|
-
import {PdfFormat} from
|
|
8
|
-
import {HtmlConverter} from
|
|
7
|
+
import { PdfFormat } from '../../../common';
|
|
8
|
+
import { HtmlConverter } from '../html.converter';
|
|
9
9
|
|
|
10
|
-
const {Response} = jest.requireActual(
|
|
11
|
-
jest.mock(
|
|
10
|
+
const { Response } = jest.requireActual('node-fetch');
|
|
11
|
+
jest.mock('node-fetch', () => jest.fn());
|
|
12
12
|
|
|
13
|
-
describe(
|
|
13
|
+
describe('HtmlConverter', () => {
|
|
14
14
|
const converter = new HtmlConverter();
|
|
15
15
|
|
|
16
|
-
describe(
|
|
17
|
-
it(
|
|
16
|
+
describe('endpoint', () => {
|
|
17
|
+
it('should route to Chromium HTML route', () => {
|
|
18
18
|
expect(converter.endpoint).toEqual(
|
|
19
|
-
|
|
19
|
+
'http://localhost:3000/forms/chromium/convert/html'
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
describe(
|
|
25
|
-
const mockPromisesAccess = jest.spyOn(promises,
|
|
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,
|
|
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(
|
|
38
|
-
it(
|
|
39
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
46
|
+
html: Buffer.from('data')
|
|
42
47
|
});
|
|
43
|
-
expect(buffer).toEqual(Buffer.from(
|
|
48
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
44
49
|
});
|
|
45
50
|
});
|
|
46
51
|
|
|
47
|
-
describe(
|
|
48
|
-
it(
|
|
49
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
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(
|
|
84
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
56
85
|
});
|
|
57
86
|
});
|
|
58
87
|
|
|
59
|
-
describe(
|
|
60
|
-
it(
|
|
61
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
64
|
-
|
|
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(
|
|
109
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
68
110
|
});
|
|
69
111
|
});
|
|
70
112
|
|
|
71
|
-
describe(
|
|
72
|
-
it(
|
|
73
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
76
|
-
|
|
117
|
+
html: Buffer.from('data'),
|
|
118
|
+
emulatedMediaType: 'screen'
|
|
77
119
|
});
|
|
78
120
|
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
79
|
-
expect(buffer).toEqual(Buffer.from(
|
|
121
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
80
122
|
});
|
|
81
123
|
});
|
|
82
124
|
|
|
83
|
-
describe(
|
|
84
|
-
it(
|
|
85
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
88
|
-
|
|
129
|
+
html: Buffer.from('data'),
|
|
130
|
+
failOnHttpStatusCodes: [499, 599]
|
|
89
131
|
});
|
|
90
132
|
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
91
|
-
expect(buffer).toEqual(Buffer.from(
|
|
133
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
92
134
|
});
|
|
93
135
|
});
|
|
94
136
|
|
|
95
|
-
describe(
|
|
96
|
-
it(
|
|
97
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
100
|
-
|
|
141
|
+
html: Buffer.from('data'),
|
|
142
|
+
skipNetworkIdleEvent: true
|
|
101
143
|
});
|
|
102
144
|
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
103
|
-
expect(buffer).toEqual(Buffer.from(
|
|
145
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
104
146
|
});
|
|
105
147
|
});
|
|
106
148
|
|
|
107
|
-
describe(
|
|
108
|
-
it(
|
|
149
|
+
describe('when all parameters are passed', () => {
|
|
150
|
+
it('should return a buffer', async () => {
|
|
109
151
|
mockPromisesAccess.mockResolvedValue();
|
|
110
|
-
mockFetch.mockResolvedValue(new Response(
|
|
152
|
+
mockFetch.mockResolvedValue(new Response('content'));
|
|
111
153
|
const buffer = await converter.convert({
|
|
112
|
-
html: Buffer.from(
|
|
113
|
-
|
|
114
|
-
|
|
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:
|
|
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(
|
|
120
|
-
expect(buffer).toEqual(Buffer.from(
|
|
162
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(9);
|
|
163
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
121
164
|
});
|
|
122
165
|
});
|
|
123
166
|
|
|
124
|
-
describe(
|
|
125
|
-
it(
|
|
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:
|
|
173
|
+
converter.convert({ html: 'path/to/index.html' })
|
|
131
174
|
).rejects.toThrow(errorMessage);
|
|
132
175
|
});
|
|
133
176
|
});
|
|
134
177
|
|
|
135
|
-
describe(
|
|
136
|
-
it(
|
|
178
|
+
describe('when fetch request fails', () => {
|
|
179
|
+
it('should throw an error', async () => {
|
|
137
180
|
const errorMessage =
|
|
138
|
-
|
|
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:
|
|
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
|
|
2
|
+
import { createReadStream, promises } from 'fs';
|
|
3
3
|
|
|
4
|
-
import FormData from
|
|
5
|
-
import fetch from
|
|
4
|
+
import FormData from 'form-data';
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
6
|
|
|
7
|
-
import {PdfFormat} from
|
|
8
|
-
import {MarkdownConverter} from
|
|
7
|
+
import { PdfFormat } from '../../../common';
|
|
8
|
+
import { MarkdownConverter } from '../markdown.converter';
|
|
9
9
|
|
|
10
|
-
const {Response} = jest.requireActual(
|
|
11
|
-
jest.mock(
|
|
10
|
+
const { Response } = jest.requireActual('node-fetch');
|
|
11
|
+
jest.mock('node-fetch', () => jest.fn());
|
|
12
12
|
|
|
13
|
-
describe(
|
|
13
|
+
describe('MarkdownConverter', () => {
|
|
14
14
|
const converter = new MarkdownConverter();
|
|
15
15
|
|
|
16
|
-
describe(
|
|
17
|
-
it(
|
|
16
|
+
describe('endpoint', () => {
|
|
17
|
+
it('should route to Chromium Markdown route', () => {
|
|
18
18
|
expect(converter.endpoint).toEqual(
|
|
19
|
-
|
|
19
|
+
'http://localhost:3000/forms/chromium/convert/markdown'
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
describe(
|
|
25
|
-
const mockPromisesAccess = jest.spyOn(promises,
|
|
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,
|
|
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(
|
|
38
|
-
it(
|
|
39
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
42
|
-
markdown: Buffer.from(
|
|
41
|
+
html: Buffer.from('data'),
|
|
42
|
+
markdown: Buffer.from('markdown')
|
|
43
43
|
});
|
|
44
|
-
expect(buffer).toEqual(Buffer.from(
|
|
44
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
54
|
-
markdown: Buffer.from(
|
|
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(
|
|
57
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
59
58
|
});
|
|
60
59
|
});
|
|
61
60
|
|
|
62
|
-
describe(
|
|
63
|
-
it(
|
|
64
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
67
|
-
markdown: Buffer.from(
|
|
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(
|
|
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(
|
|
76
|
-
it(
|
|
77
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
80
|
-
markdown: Buffer.from(
|
|
81
|
-
|
|
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(
|
|
96
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
85
97
|
});
|
|
86
98
|
});
|
|
87
99
|
|
|
88
|
-
describe(
|
|
89
|
-
it(
|
|
90
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
93
|
-
markdown: Buffer.from(
|
|
94
|
-
|
|
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(
|
|
110
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
98
111
|
});
|
|
99
112
|
});
|
|
100
113
|
|
|
101
|
-
describe(
|
|
102
|
-
it(
|
|
103
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
106
|
-
markdown: Buffer.from(
|
|
107
|
-
|
|
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(
|
|
136
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
112
137
|
});
|
|
113
138
|
});
|
|
114
139
|
|
|
115
|
-
describe(
|
|
116
|
-
it(
|
|
117
|
-
mockFetch.mockResolvedValue(new Response(
|
|
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(
|
|
120
|
-
markdown: Buffer.from(
|
|
121
|
-
header: Buffer.from(
|
|
122
|
-
footer: Buffer.from(
|
|
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:
|
|
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(
|
|
153
|
+
expect(buffer).toEqual(Buffer.from('content'));
|
|
129
154
|
});
|
|
130
155
|
});
|
|
131
156
|
|
|
132
|
-
describe(
|
|
133
|
-
it(
|
|
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:
|
|
141
|
-
markdown:
|
|
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(
|
|
148
|
-
it(
|
|
172
|
+
describe('when fetch request fails', () => {
|
|
173
|
+
it('should throw an error', async () => {
|
|
149
174
|
const errorMessage =
|
|
150
|
-
|
|
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:
|
|
156
|
-
markdown:
|
|
180
|
+
html: 'path/to/index.html',
|
|
181
|
+
markdown: 'path/to/file.md'
|
|
157
182
|
})
|
|
158
183
|
).rejects.toThrow(errorMessage);
|
|
159
184
|
});
|