chromiumly 3.2.1 → 3.3.1

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 (77) hide show
  1. package/README.md +21 -2
  2. package/dist/chromium/converters/converter.js +1 -1
  3. package/dist/chromium/converters/converter.js.map +1 -1
  4. package/dist/chromium/converters/html.converter.js +1 -1
  5. package/dist/chromium/converters/html.converter.js.map +1 -1
  6. package/dist/chromium/converters/markdown.converter.js +1 -1
  7. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  8. package/dist/chromium/converters/url.converter.js +1 -1
  9. package/dist/chromium/converters/url.converter.js.map +1 -1
  10. package/dist/chromium/screenshots/html.screenshot.js +1 -1
  11. package/dist/chromium/screenshots/html.screenshot.js.map +1 -1
  12. package/dist/chromium/screenshots/markdown.screenshot.js +1 -1
  13. package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -1
  14. package/dist/chromium/screenshots/screenshot.js +1 -1
  15. package/dist/chromium/screenshots/screenshot.js.map +1 -1
  16. package/dist/chromium/screenshots/url.screenshot.js +1 -1
  17. package/dist/chromium/screenshots/url.screenshot.js.map +1 -1
  18. package/dist/gotenberg.d.ts +1 -1
  19. package/dist/gotenberg.js +4 -2
  20. package/dist/gotenberg.js.map +1 -1
  21. package/dist/libre-office/libre-office.js +2 -2
  22. package/dist/libre-office/libre-office.js.map +1 -1
  23. package/dist/main.config.d.ts +30 -3
  24. package/dist/main.config.js +42 -3
  25. package/dist/main.config.js.map +1 -1
  26. package/dist/main.d.ts +1 -0
  27. package/dist/main.js +3 -1
  28. package/dist/main.js.map +1 -1
  29. package/dist/pdf-engines/pdf-engines.js +8 -8
  30. package/dist/pdf-engines/pdf-engines.js.map +1 -1
  31. package/dist/pdf-engines/utils/pdf-engines.utils.js +5 -5
  32. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -1
  33. package/package.json +16 -11
  34. package/src/.prettierrc.yml +0 -4
  35. package/src/chromium/converters/converter.ts +0 -22
  36. package/src/chromium/converters/html.converter.ts +0 -134
  37. package/src/chromium/converters/markdown.converter.ts +0 -129
  38. package/src/chromium/converters/tests/html.converter.test.ts +0 -190
  39. package/src/chromium/converters/tests/markdown.converter.test.ts +0 -187
  40. package/src/chromium/converters/tests/url.converter.test.ts +0 -164
  41. package/src/chromium/converters/url.converter.ts +0 -125
  42. package/src/chromium/index.ts +0 -6
  43. package/src/chromium/interfaces/common.types.ts +0 -15
  44. package/src/chromium/interfaces/converter.types.ts +0 -45
  45. package/src/chromium/interfaces/screenshot.types.ts +0 -15
  46. package/src/chromium/screenshots/html.screenshot.ts +0 -105
  47. package/src/chromium/screenshots/markdown.screenshot.ts +0 -100
  48. package/src/chromium/screenshots/screenshot.ts +0 -22
  49. package/src/chromium/screenshots/tests/html.screenshot.test.ts +0 -192
  50. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +0 -176
  51. package/src/chromium/screenshots/tests/url.screenshot.test.ts +0 -166
  52. package/src/chromium/screenshots/url.screenshot.ts +0 -96
  53. package/src/chromium/utils/converter.utils.ts +0 -187
  54. package/src/chromium/utils/screenshot.utils.ts +0 -127
  55. package/src/chromium/utils/tests/converter.utils.test.ts +0 -496
  56. package/src/chromium/utils/tests/screenshot.utils.test.ts +0 -338
  57. package/src/common/constants.ts +0 -9
  58. package/src/common/gotenberg.utils.ts +0 -86
  59. package/src/common/index.ts +0 -3
  60. package/src/common/tests/gotenberg.utils.test.ts +0 -141
  61. package/src/common/types.ts +0 -7
  62. package/src/gotenberg.ts +0 -54
  63. package/src/libre-office/index.ts +0 -1
  64. package/src/libre-office/interfaces/libre-office.types.ts +0 -156
  65. package/src/libre-office/libre-office.ts +0 -61
  66. package/src/libre-office/tests/libre-office.test.ts +0 -56
  67. package/src/libre-office/utils/constants.ts +0 -132
  68. package/src/libre-office/utils/libre-office.utils.ts +0 -128
  69. package/src/libre-office/utils/tests/libre-office.utils.test.ts +0 -156
  70. package/src/main.config.ts +0 -106
  71. package/src/main.ts +0 -11
  72. package/src/pdf-engines/index.ts +0 -1
  73. package/src/pdf-engines/interfaces/pdf-engines.types.ts +0 -10
  74. package/src/pdf-engines/pdf-engines.ts +0 -156
  75. package/src/pdf-engines/tests/pdf.engine.test.ts +0 -163
  76. package/src/pdf-engines/utils/pdf-engines.utils.ts +0 -68
  77. package/src/pdf-engines/utils/tests/pdf-engines.utils.test.ts +0 -71
@@ -1,192 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream, promises } from 'fs';
3
-
4
- import fetch from 'node-fetch';
5
- import FormData from 'form-data';
6
-
7
- import { HtmlScreenshot } from '../html.screenshot';
8
-
9
- const { Response } = jest.requireActual('node-fetch');
10
- jest.mock('node-fetch', () => jest.fn());
11
-
12
- describe('HtmlScreenshot', () => {
13
- const screenshot = new HtmlScreenshot();
14
-
15
- describe('endpoint', () => {
16
- it('should route to Chromium HTML route', () => {
17
- expect(screenshot.endpoint).toEqual(
18
- 'http://localhost:3000/forms/chromium/screenshot/html'
19
- );
20
- });
21
- });
22
-
23
- describe('capture', () => {
24
- const mockPromisesAccess = jest.spyOn(promises, 'access');
25
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
26
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
27
-
28
- const assets = [
29
- { file: Buffer.from('asset1'), name: 'asset1' },
30
- { file: Buffer.from('asset2'), name: 'asset2' }
31
- ];
32
-
33
- beforeEach(() => {
34
- (createReadStream as jest.Mock) = jest.fn();
35
- });
36
-
37
- afterEach(() => {
38
- jest.resetAllMocks();
39
- });
40
-
41
- describe('when html parameter is passed', () => {
42
- it('should return a buffer', async () => {
43
- mockFetch.mockResolvedValue(new Response('content'));
44
- const buffer = await screenshot.capture({
45
- html: Buffer.from('data')
46
- });
47
- expect(buffer).toEqual(Buffer.from('content'));
48
- });
49
- });
50
-
51
- describe('when image properties parameter is passed', () => {
52
- it('should return a buffer', async () => {
53
- mockFetch.mockResolvedValue(new Response('content'));
54
- const buffer = await screenshot.capture({
55
- html: Buffer.from('data'),
56
- properties: { format: 'jpeg', quality: 50 }
57
- });
58
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
59
- expect(buffer).toEqual(Buffer.from('content'));
60
- });
61
- });
62
-
63
- describe('when header parameter is passed', () => {
64
- it('should return a buffer', async () => {
65
- mockFetch.mockResolvedValue(new Response('content'));
66
- const buffer = await screenshot.capture({
67
- html: Buffer.from('data'),
68
- header: Buffer.from('header')
69
- });
70
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
71
- expect(buffer).toEqual(Buffer.from('content'));
72
- });
73
- });
74
-
75
- describe('when footer parameter is passed', () => {
76
- it('should return a buffer', async () => {
77
- mockFetch.mockResolvedValue(new Response('content'));
78
- const buffer = await screenshot.capture({
79
- html: Buffer.from('data'),
80
- footer: Buffer.from('footer')
81
- });
82
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
83
- expect(buffer).toEqual(Buffer.from('content'));
84
- });
85
- });
86
-
87
- describe('when assets parameter is passed', () => {
88
- it('should return a buffer', async () => {
89
- mockFetch.mockResolvedValue(new Response('content'));
90
- const buffer = await screenshot.capture({
91
- html: Buffer.from('data'),
92
- assets
93
- });
94
-
95
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
96
- expect(buffer).toEqual(Buffer.from('content'));
97
- });
98
- });
99
-
100
- describe('when emulatedMediaType parameter is passed', () => {
101
- it('should return a buffer', async () => {
102
- mockFetch.mockResolvedValue(new Response('content'));
103
- const buffer = await screenshot.capture({
104
- html: Buffer.from('data'),
105
- emulatedMediaType: 'screen'
106
- });
107
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
108
- expect(buffer).toEqual(Buffer.from('content'));
109
- });
110
- });
111
-
112
- describe('when failOnHttpStatusCodes parameter is passed', () => {
113
- it('should return a buffer', async () => {
114
- mockFetch.mockResolvedValue(new Response('content'));
115
- const buffer = await screenshot.capture({
116
- html: Buffer.from('data'),
117
- failOnHttpStatusCodes: [499, 599]
118
- });
119
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
120
- expect(buffer).toEqual(Buffer.from('content'));
121
- });
122
- });
123
-
124
- describe('when skipNetworkIdleEvent parameter is passed', () => {
125
- it('should return a buffer', async () => {
126
- mockFetch.mockResolvedValue(new Response('content'));
127
- const buffer = await screenshot.capture({
128
- html: Buffer.from('data'),
129
- skipNetworkIdleEvent: true
130
- });
131
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
132
- expect(buffer).toEqual(Buffer.from('content'));
133
- });
134
- });
135
-
136
- describe('when optimizeForSpeed parameter is passed', () => {
137
- it('should return a buffer', async () => {
138
- mockFetch.mockResolvedValue(new Response('content'));
139
- const buffer = await screenshot.capture({
140
- html: Buffer.from('data'),
141
- optimizeForSpeed: true
142
- });
143
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
144
- expect(buffer).toEqual(Buffer.from('content'));
145
- });
146
- });
147
-
148
- describe('when all parameters are passed', () => {
149
- it('should return a buffer', async () => {
150
- mockPromisesAccess.mockResolvedValue();
151
- mockFetch.mockResolvedValue(new Response('content'));
152
- const buffer = await screenshot.capture({
153
- html: Buffer.from('data'),
154
- assets,
155
- header: Buffer.from('header'),
156
- footer: Buffer.from('footer'),
157
- emulatedMediaType: 'screen',
158
- failOnHttpStatusCodes: [499, 599],
159
- skipNetworkIdleEvent: true,
160
- failOnConsoleExceptions: true,
161
- properties: { format: 'jpeg', quality: 50 },
162
- optimizeForSpeed: true
163
- });
164
- expect(mockFormDataAppend).toHaveBeenCalledTimes(12);
165
- expect(buffer).toEqual(Buffer.from('content'));
166
- });
167
- });
168
-
169
- describe('when file does not exist', () => {
170
- it('should throw an error', async () => {
171
- const errorMessage =
172
- "ENOENT: no such file or directory, access 'path/to/index.html'";
173
- mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
174
- await expect(() =>
175
- screenshot.capture({ html: 'path/to/index.html' })
176
- ).rejects.toThrow(errorMessage);
177
- });
178
- });
179
-
180
- describe('when fetch request fails', () => {
181
- it('should throw an error', async () => {
182
- const errorMessage =
183
- 'FetchError: request to http://localhost:3000/forms/chromium/screenshot/html failed';
184
- mockPromisesAccess.mockResolvedValue();
185
- mockFetch.mockRejectedValue(new Error(errorMessage));
186
- await expect(() =>
187
- screenshot.capture({ html: 'path/to/index.html' })
188
- ).rejects.toThrow(errorMessage);
189
- });
190
- });
191
- });
192
- });
@@ -1,176 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream, promises } from 'fs';
3
-
4
- import FormData from 'form-data';
5
- import fetch from 'node-fetch';
6
-
7
- import { MarkdownScreenshot } from '../markdown.screenshot';
8
-
9
- const { Response } = jest.requireActual('node-fetch');
10
- jest.mock('node-fetch', () => jest.fn());
11
-
12
- describe('MarkdownScreenshot', () => {
13
- const screenshot = new MarkdownScreenshot();
14
-
15
- describe('endpoint', () => {
16
- it('should route to Chromium Markdown route', () => {
17
- expect(screenshot.endpoint).toEqual(
18
- 'http://localhost:3000/forms/chromium/screenshot/markdown'
19
- );
20
- });
21
- });
22
-
23
- describe('capture', () => {
24
- const mockPromisesAccess = jest.spyOn(promises, 'access');
25
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
26
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
27
-
28
- beforeEach(() => {
29
- (createReadStream as jest.Mock) = jest.fn();
30
- });
31
-
32
- afterEach(() => {
33
- jest.resetAllMocks();
34
- });
35
-
36
- describe('when html and markdown parameters are passed', () => {
37
- it('should return a buffer', async () => {
38
- mockFetch.mockResolvedValue(new Response('content'));
39
- const buffer = await screenshot.capture({
40
- html: Buffer.from('data'),
41
- markdown: Buffer.from('markdown')
42
- });
43
- expect(buffer).toEqual(Buffer.from('content'));
44
- });
45
- });
46
-
47
- describe('when image properties parameter is passed', () => {
48
- it('should return a buffer', async () => {
49
- mockFetch.mockResolvedValue(new Response('content'));
50
- const buffer = await screenshot.capture({
51
- html: Buffer.from('data'),
52
- markdown: Buffer.from('markdown'),
53
- properties: { format: 'jpeg', quality: 50 }
54
- });
55
- expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
56
- expect(buffer).toEqual(Buffer.from('content'));
57
- });
58
- });
59
-
60
- describe('when header parameter is passed', () => {
61
- it('should return a buffer', async () => {
62
- mockFetch.mockResolvedValue(new Response('content'));
63
- const buffer = await screenshot.capture({
64
- html: Buffer.from('data'),
65
- markdown: Buffer.from('markdown'),
66
- header: Buffer.from('header')
67
- });
68
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
69
- expect(buffer).toEqual(Buffer.from('content'));
70
- });
71
- });
72
-
73
- describe('when footer parameter is passed', () => {
74
- it('should return a buffer', async () => {
75
- mockFetch.mockResolvedValue(new Response('content'));
76
- const buffer = await screenshot.capture({
77
- html: Buffer.from('data'),
78
- markdown: Buffer.from('markdown'),
79
- footer: Buffer.from('footer')
80
- });
81
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
82
- expect(buffer).toEqual(Buffer.from('content'));
83
- });
84
- });
85
-
86
- describe('when emulatedMediaType parameter is passed', () => {
87
- it('should return a buffer', async () => {
88
- mockFetch.mockResolvedValue(new Response('content'));
89
- const buffer = await screenshot.capture({
90
- html: Buffer.from('data'),
91
- markdown: Buffer.from('markdown'),
92
- emulatedMediaType: 'screen'
93
- });
94
-
95
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
96
- expect(buffer).toEqual(Buffer.from('content'));
97
- });
98
- });
99
-
100
- describe('when failOnHttpStatusCodes parameter is passed', () => {
101
- it('should return a buffer', async () => {
102
- mockFetch.mockResolvedValue(new Response('content'));
103
- const buffer = await screenshot.capture({
104
- html: Buffer.from('data'),
105
- markdown: Buffer.from('markdown'),
106
- failOnHttpStatusCodes: [499, 599]
107
- });
108
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
109
- expect(buffer).toEqual(Buffer.from('content'));
110
- });
111
- });
112
-
113
- describe('when skipNetworkIdleEvent parameter is passed', () => {
114
- it('should return a buffer', async () => {
115
- mockFetch.mockResolvedValue(new Response('content'));
116
- const buffer = await screenshot.capture({
117
- html: Buffer.from('data'),
118
- markdown: Buffer.from('markdown'),
119
- skipNetworkIdleEvent: true
120
- });
121
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
122
- expect(buffer).toEqual(Buffer.from('content'));
123
- });
124
- });
125
-
126
- describe('when all parameters are passed', () => {
127
- it('should return a buffer', async () => {
128
- mockFetch.mockResolvedValue(new Response('content'));
129
- const buffer = await screenshot.capture({
130
- html: Buffer.from('data'),
131
- markdown: Buffer.from('markdown'),
132
- header: Buffer.from('header'),
133
- footer: Buffer.from('footer'),
134
- emulatedMediaType: 'screen',
135
- failOnHttpStatusCodes: [499, 599],
136
- skipNetworkIdleEvent: true,
137
- failOnConsoleExceptions: true,
138
- properties: { format: 'jpeg', quality: 50 },
139
- optimizeForSpeed: true
140
- });
141
- expect(mockFormDataAppend).toHaveBeenCalledTimes(11);
142
- expect(buffer).toEqual(Buffer.from('content'));
143
- });
144
- });
145
-
146
- describe('when file does not exist', () => {
147
- it('should throw an error', async () => {
148
- const errorMessage =
149
- "ENOENT: no such file or directory, access 'path/to/index.html'";
150
- mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
151
-
152
- await expect(() =>
153
- screenshot.capture({
154
- html: 'path/to/index.html',
155
- markdown: 'path/to/file.md'
156
- })
157
- ).rejects.toThrow(errorMessage);
158
- });
159
- });
160
-
161
- describe('when fetch request fails', () => {
162
- it('should throw an error', async () => {
163
- const errorMessage =
164
- 'FetchError: request to http://localhost:3000/forms/chromium/screenshot/html failed';
165
- mockPromisesAccess.mockResolvedValue();
166
- mockFetch.mockRejectedValue(new Error(errorMessage));
167
- await expect(() =>
168
- screenshot.capture({
169
- html: 'path/to/index.html',
170
- markdown: 'path/to/file.md'
171
- })
172
- ).rejects.toThrow(errorMessage);
173
- });
174
- });
175
- });
176
- });
@@ -1,166 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream } from 'fs';
3
- import FormData from 'form-data';
4
- import fetch from 'node-fetch';
5
-
6
- import { UrlScreenshot } from './../url.screenshot';
7
-
8
- const { Response } = jest.requireActual('node-fetch');
9
- jest.mock('node-fetch', () => jest.fn());
10
-
11
- describe('URLScreenshot', () => {
12
- const screenshot = new UrlScreenshot();
13
-
14
- describe('endpoint', () => {
15
- it('should route to Chromium HTML route', () => {
16
- expect(screenshot.endpoint).toEqual(
17
- 'http://localhost:3000/forms/chromium/screenshot/url'
18
- );
19
- });
20
- });
21
-
22
- describe('capture', () => {
23
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
24
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
25
-
26
- beforeEach(() => {
27
- (createReadStream as jest.Mock) = jest.fn();
28
- });
29
-
30
- afterEach(() => {
31
- jest.resetAllMocks();
32
- });
33
-
34
- describe('when URL is valid', () => {
35
- it('should return a buffer', async () => {
36
- mockFetch.mockResolvedValueOnce(new Response('content'));
37
- const buffer = await screenshot.capture({
38
- url: 'http://www.example.com/'
39
- });
40
- expect(buffer).toEqual(Buffer.from('content'));
41
- });
42
- });
43
-
44
- describe('when header parameter is passed', () => {
45
- it('should return a buffer', async () => {
46
- mockFetch.mockResolvedValueOnce(new Response('content'));
47
- const buffer = await screenshot.capture({
48
- url: 'http://www.example.com/',
49
- header: Buffer.from('header')
50
- });
51
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
52
- expect(buffer).toEqual(Buffer.from('content'));
53
- });
54
- });
55
-
56
- describe('when footer parameter is passed', () => {
57
- it('should return a buffer', async () => {
58
- mockFetch.mockResolvedValueOnce(new Response('content'));
59
- const buffer = await screenshot.capture({
60
- url: 'http://www.example.com/',
61
- footer: Buffer.from('footer')
62
- });
63
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
64
- expect(buffer).toEqual(Buffer.from('content'));
65
- });
66
- });
67
-
68
- describe('when image properties parameter is passed', () => {
69
- it('should return a buffer', async () => {
70
- mockFetch.mockResolvedValueOnce(new Response('content'));
71
- const buffer = await screenshot.capture({
72
- url: 'http://www.example.com/',
73
- properties: { format: 'jpeg', quality: 50 }
74
- });
75
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
76
- expect(buffer).toEqual(Buffer.from('content'));
77
- });
78
- });
79
-
80
- describe('when emulatedMediaType parameter is passed', () => {
81
- it('should return a buffer', async () => {
82
- mockFetch.mockResolvedValue(new Response('content'));
83
- const buffer = await screenshot.capture({
84
- url: 'http://www.example.com/',
85
- emulatedMediaType: 'screen'
86
- });
87
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
88
- expect(buffer).toEqual(Buffer.from('content'));
89
- });
90
- });
91
-
92
- describe('when failOnHttpStatusCodes parameter is passed', () => {
93
- it('should return a buffer', async () => {
94
- mockFetch.mockResolvedValue(new Response('content'));
95
- const buffer = await screenshot.capture({
96
- url: 'http://www.example.com/',
97
- failOnHttpStatusCodes: [499, 599]
98
- });
99
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
100
- expect(buffer).toEqual(Buffer.from('content'));
101
- });
102
- });
103
-
104
- describe('when skipNetworkIdleEvent parameter is passed', () => {
105
- it('should return a buffer', async () => {
106
- mockFetch.mockResolvedValue(new Response('content'));
107
- const buffer = await screenshot.capture({
108
- url: 'http://www.example.com/',
109
- skipNetworkIdleEvent: true
110
- });
111
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
112
- expect(buffer).toEqual(Buffer.from('content'));
113
- });
114
- });
115
-
116
- describe('when optimizeForSpeed parameter is passed', () => {
117
- it('should return a buffer', async () => {
118
- mockFetch.mockResolvedValue(new Response('content'));
119
- const buffer = await screenshot.capture({
120
- url: 'http://www.example.com/',
121
- optimizeForSpeed: true
122
- });
123
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
124
- expect(buffer).toEqual(Buffer.from('content'));
125
- });
126
- });
127
-
128
- describe('when all parameters are passed', () => {
129
- it('should return a buffer', async () => {
130
- mockFetch.mockResolvedValue(new Response('content'));
131
- const buffer = await screenshot.capture({
132
- url: 'http://www.example.com/',
133
- header: Buffer.from('header'),
134
- footer: Buffer.from('footer'),
135
- emulatedMediaType: 'screen',
136
- failOnHttpStatusCodes: [499, 599],
137
- skipNetworkIdleEvent: true,
138
- failOnConsoleExceptions: true,
139
- properties: { format: 'jpeg', quality: 50 },
140
- optimizeForSpeed: true
141
- });
142
- expect(mockFormDataAppend).toHaveBeenCalledTimes(10);
143
- expect(buffer).toEqual(Buffer.from('content'));
144
- });
145
- });
146
-
147
- describe('when URL is invalid', () => {
148
- it('should throw an error', async () => {
149
- await expect(() =>
150
- screenshot.capture({ url: 'invalid url' })
151
- ).rejects.toThrow('Invalid URL');
152
- });
153
- });
154
-
155
- describe('when fetch request fails', () => {
156
- it('should throw an error', async () => {
157
- const errorMessage =
158
- 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
159
- mockFetch.mockRejectedValueOnce(new Error(errorMessage));
160
- await expect(() =>
161
- screenshot.capture({ url: 'http://www.example.com/' })
162
- ).rejects.toThrow(errorMessage);
163
- });
164
- });
165
- });
166
- });
@@ -1,96 +0,0 @@
1
- import { URL } from 'url';
2
- import FormData from 'form-data';
3
- import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
- import { ImageProperties } from '../interfaces/screenshot.types';
5
- import { ScreenshotUtils } from '../utils/screenshot.utils';
6
- import { Screenshot } from './screenshot';
7
- import { ChromiumRoute, Chromiumly } from '../../main.config';
8
- import { EmulatedMediaType } from '../interfaces/common.types';
9
-
10
- /**
11
- * Class representing a URL screenshot that extends the base screenshot class.
12
- * This class is used to screenshot a URL using Gotenberg service.
13
- *
14
- * @extends Screenshot
15
- */
16
- export class UrlScreenshot extends Screenshot {
17
- /**
18
- * Creates an instance of UrlScreenshot.
19
- * Initializes the screenshot with the URL screenshot route.
20
- */
21
- constructor() {
22
- super(ChromiumRoute.URL);
23
- }
24
-
25
- /**
26
- * Screenshots URL.
27
- *
28
- * @param {Object} options - Screenshot options.
29
- * @param {string} options.url - The URL of the content to be screenshoted
30
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
31
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
32
- * @param {ImageProperties} [options.properties] - Image properties for the screenshot.
33
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
34
- * @param {string} [options.waitDelay] - Delay before the screenshot process starts.
35
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
36
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
37
- * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
38
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
39
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
40
- * @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
41
- * @returns {Promise<Buffer>} A Promise resolving to the image buffer.
42
- */
43
- async capture({
44
- url,
45
- header,
46
- footer,
47
- properties,
48
- emulatedMediaType,
49
- waitDelay,
50
- waitForExpression,
51
- extraHttpHeaders,
52
- failOnHttpStatusCodes,
53
- failOnConsoleExceptions,
54
- skipNetworkIdleEvent,
55
- optimizeForSpeed
56
- }: {
57
- url: string;
58
- header?: PathLikeOrReadStream;
59
- footer?: PathLikeOrReadStream;
60
- properties?: ImageProperties;
61
- emulatedMediaType?: EmulatedMediaType;
62
- waitDelay?: string;
63
- waitForExpression?: string;
64
- extraHttpHeaders?: Record<string, string>;
65
- failOnHttpStatusCodes?: number[];
66
- failOnConsoleExceptions?: boolean;
67
- skipNetworkIdleEvent?: boolean;
68
- optimizeForSpeed?: boolean;
69
- }): Promise<Buffer> {
70
- const _url = new URL(url);
71
- const data = new FormData();
72
-
73
- data.append('url', _url.href);
74
-
75
- await ScreenshotUtils.customize(data, {
76
- header,
77
- footer,
78
- properties,
79
- emulatedMediaType,
80
- waitDelay,
81
- waitForExpression,
82
- extraHttpHeaders,
83
- failOnHttpStatusCodes,
84
- failOnConsoleExceptions,
85
- skipNetworkIdleEvent,
86
- optimizeForSpeed
87
- });
88
-
89
- return GotenbergUtils.fetch(
90
- this.endpoint,
91
- data,
92
- Chromiumly.GOTENBERG_API_BASIC_AUTH_USERNAME,
93
- Chromiumly.GOTENBERG_API_BASIC_AUTH_PASSWORD
94
- );
95
- }
96
- }