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