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,5 +1,7 @@
1
- import FormData from "form-data";
2
- import fetch from "node-fetch";
1
+ import { constants, createReadStream, ReadStream, promises } from 'fs';
2
+ import FormData from 'form-data';
3
+ import fetch from 'node-fetch';
4
+ import { PathLikeOrReadStream } from './types';
3
5
 
4
6
  /**
5
7
  * Utility class for common tasks related to the Gotenberg service.
@@ -12,7 +14,10 @@ export class GotenbergUtils {
12
14
  * @param {string} message - The error message to throw if the condition is false.
13
15
  * @throws {Error} Throws an error with the specified message if the condition is false.
14
16
  */
15
- public static assert(condition: boolean, message: string): asserts condition {
17
+ public static assert(
18
+ condition: boolean,
19
+ message: string
20
+ ): asserts condition {
16
21
  if (!condition) {
17
22
  throw new Error(message);
18
23
  }
@@ -26,13 +31,16 @@ export class GotenbergUtils {
26
31
  * @returns {Promise<Buffer>} A Promise that resolves to the response body as a Buffer.
27
32
  * @throws {Error} Throws an error if the HTTP response status is not OK.
28
33
  */
29
- public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
34
+ public static async fetch(
35
+ endpoint: string,
36
+ data: FormData
37
+ ): Promise<Buffer> {
30
38
  const response = await fetch(endpoint, {
31
- method: "post",
39
+ method: 'post',
32
40
  body: data,
33
41
  headers: {
34
- ...data.getHeaders(),
35
- },
42
+ ...data.getHeaders()
43
+ }
36
44
  });
37
45
 
38
46
  if (!response.ok) {
@@ -41,4 +49,27 @@ export class GotenbergUtils {
41
49
 
42
50
  return response.buffer();
43
51
  }
44
- }
52
+
53
+ /**
54
+ * Adds a file to the FormData object.
55
+ *
56
+ * @param {FormData} data - The FormData object to which the file will be added.
57
+ * @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
58
+ * @param {string} name - The name to be used for the file in the FormData.
59
+ * @returns {Promise<void>} A Promise that resolves once the file has been added.
60
+ */
61
+ public static async addFile(
62
+ data: FormData,
63
+ file: PathLikeOrReadStream,
64
+ name: string
65
+ ) {
66
+ if (Buffer.isBuffer(file)) {
67
+ data.append('files', file, name);
68
+ } else if (file instanceof ReadStream) {
69
+ data.append('files', file, name);
70
+ } else {
71
+ await promises.access(file, constants.R_OK);
72
+ data.append('files', createReadStream(file), name);
73
+ }
74
+ }
75
+ }
@@ -1,3 +1,3 @@
1
- export {PdfFormat} from "./constants";
2
- export {GotenbergUtils} from "./gotenberg.utils";
3
- export {PathLikeOrReadStream} from "./types"
1
+ export { PdfFormat } from './constants';
2
+ export { GotenbergUtils } from './gotenberg.utils';
3
+ export { PathLikeOrReadStream } from './types';
@@ -1,69 +1,76 @@
1
- import fetch from "node-fetch";
2
- import FormData from "form-data";
1
+ import fetch from 'node-fetch';
2
+ import FormData from 'form-data';
3
3
 
4
- import {GotenbergUtils} from "./../gotenberg.utils";
4
+ import { GotenbergUtils } from './../gotenberg.utils';
5
5
 
6
- const {Response, FetchError} = jest.requireActual("node-fetch");
6
+ const { Response, FetchError } = jest.requireActual('node-fetch');
7
7
 
8
- jest.mock("node-fetch", () => jest.fn());
8
+ jest.mock('node-fetch', () => jest.fn());
9
9
 
10
- describe("GotenbergUtils", () => {
10
+ describe('GotenbergUtils', () => {
11
11
  afterEach(() => {
12
12
  jest.resetAllMocks();
13
13
  });
14
14
 
15
- describe("assert", () => {
16
- const errorMessage = "error message";
17
- describe("when condition is true", () => {
18
- it("should pass", () => {
19
- expect(() => GotenbergUtils.assert(true, errorMessage)).not.toThrow();
15
+ describe('assert', () => {
16
+ const errorMessage = 'error message';
17
+ describe('when condition is true', () => {
18
+ it('should pass', () => {
19
+ expect(() =>
20
+ GotenbergUtils.assert(true, errorMessage)
21
+ ).not.toThrow();
20
22
  });
21
23
  });
22
- describe("when condition is false", () => {
23
- it("should return error message", () => {
24
- expect(() => GotenbergUtils.assert(false, errorMessage)).toThrow(
25
- errorMessage
26
- );
24
+ describe('when condition is false', () => {
25
+ it('should return error message', () => {
26
+ expect(() =>
27
+ GotenbergUtils.assert(false, errorMessage)
28
+ ).toThrow(errorMessage);
27
29
  });
28
30
  });
29
31
  });
30
32
 
31
- describe("fetch", () => {
33
+ describe('fetch', () => {
32
34
  const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
33
35
  const data = new FormData();
34
- const endpoint = "http://localhost:3000/forms/chromium/convert/html";
36
+ const endpoint = 'http://localhost:3000/forms/chromium/convert/html';
35
37
 
36
- describe("when fetch request succeeds", () => {
37
- it("should return a buffer", async () => {
38
- mockFetch.mockResolvedValueOnce(new Response("content"));
38
+ describe('when fetch request succeeds', () => {
39
+ it('should return a buffer', async () => {
40
+ mockFetch.mockResolvedValueOnce(new Response('content'));
39
41
  const response = await GotenbergUtils.fetch(endpoint, data);
40
- await expect(response).toEqual(Buffer.from("content"));
42
+ await expect(response).toEqual(Buffer.from('content'));
41
43
  });
42
44
  });
43
45
 
44
- describe("when fetch request fails", () => {
45
- describe("when there is a known error", () => {
46
- it("should throw an error", async () => {
46
+ describe('when fetch request fails', () => {
47
+ describe('when there is a known error', () => {
48
+ it('should throw an error', async () => {
47
49
  const errorMessage =
48
- "FetchError: request to http://localhost:3000/forms/chromium/convert/html failed";
49
- mockFetch.mockRejectedValueOnce(new FetchError(errorMessage));
50
+ 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
51
+ mockFetch.mockRejectedValueOnce(
52
+ new FetchError(errorMessage)
53
+ );
50
54
  await expect(() =>
51
55
  GotenbergUtils.fetch(endpoint, data)
52
56
  ).rejects.toThrow(errorMessage);
53
57
  });
54
58
  });
55
59
 
56
- describe("when there is an unknown error", () => {
57
- it("should throw an error", async () => {
60
+ describe('when there is an unknown error', () => {
61
+ it('should throw an error', async () => {
58
62
  mockFetch.mockResolvedValueOnce(
59
63
  new Response(
60
64
  {},
61
- {status: 500, statusText: "Internal server error"}
65
+ {
66
+ status: 500,
67
+ statusText: 'Internal server error'
68
+ }
62
69
  )
63
70
  );
64
71
  await expect(() =>
65
72
  GotenbergUtils.fetch(endpoint, data)
66
- ).rejects.toThrow("500 Internal server error");
73
+ ).rejects.toThrow('500 Internal server error');
67
74
  });
68
75
  });
69
76
  });
@@ -1,3 +1,3 @@
1
- import {PathLike, ReadStream} from "fs";
1
+ import { PathLike, ReadStream } from 'fs';
2
2
 
3
- export type PathLikeOrReadStream = PathLike | ReadStream
3
+ export type PathLikeOrReadStream = PathLike | ReadStream;
package/src/gotenberg.ts CHANGED
@@ -1,18 +1,18 @@
1
- process.env.SUPPRESS_NO_CONFIG_WARNING = "y";
1
+ process.env.SUPPRESS_NO_CONFIG_WARNING = 'y';
2
2
 
3
- import * as dotenv from "dotenv";
4
- import * as path from "path";
5
- import config from "config";
3
+ import * as dotenv from 'dotenv';
4
+ import * as path from 'path';
5
+ import config from 'config';
6
6
 
7
7
  // Load endpoint from environment-specific file (e.g., .env.development)
8
8
  const envFile = `.env.${process.env.NODE_ENV}`;
9
- const envFileFallback = ".env";
9
+ const envFileFallback = '.env';
10
10
 
11
- const dotenvConfig = dotenv.config({path: path.resolve(envFile)});
11
+ const dotenvConfig = dotenv.config({ path: path.resolve(envFile) });
12
12
 
13
13
  // Fallback to loading the default environment file.
14
14
  if (dotenvConfig.error) {
15
- dotenv.config({path: path.resolve(envFileFallback)});
15
+ dotenv.config({ path: path.resolve(envFileFallback) });
16
16
  }
17
17
 
18
18
  /**
@@ -25,6 +25,6 @@ export class Gotenberg {
25
25
  * @type {string}
26
26
  */
27
27
  public static endpoint: string =
28
- process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
28
+ process.env.GOTENBERG_ENDPOINT ||
29
+ config.get<string>('gotenberg.endpoint');
29
30
  }
30
-
@@ -1,2 +1,2 @@
1
- export {PageProperties} from "./interfaces/libre-office.types";
2
- export {LibreOfficeUtils} from "./utils/libre-office.utils";
1
+ export { PageProperties } from './interfaces/libre-office.types';
2
+ export { LibreOfficeUtils } from './utils/libre-office.utils';
@@ -1,78 +1,82 @@
1
1
  export const LIBRE_OFFICE_EXTENSIONS = [
2
- "bib",
3
- "doc",
4
- "xml",
5
- "docx",
6
- "fodt",
7
- "html",
8
- "ltx",
9
- "txt",
10
- "odt",
11
- "ott",
12
- "pdb",
13
- "pdf",
14
- "psw",
15
- "rtf",
16
- "sdw",
17
- "stw",
18
- "sxw",
19
- "uot",
20
- "vor",
21
- "wps",
22
- "epub",
23
- "png",
24
- "bmp",
25
- "emf",
26
- "eps",
27
- "fodg",
28
- "gif",
29
- "jpg",
30
- "met",
31
- "odd",
32
- "otg",
33
- "pbm",
34
- "pct",
35
- "pgm",
36
- "ppm",
37
- "ras",
38
- "std",
39
- "svg",
40
- "svm",
41
- "swf",
42
- "sxd",
43
- "sxw",
44
- "tiff",
45
- "xhtml",
46
- "xpm",
47
- "fodp",
48
- "potm",
49
- "pot",
50
- "pptx",
51
- "pps",
52
- "ppt",
53
- "pwp",
54
- "sda",
55
- "sdd",
56
- "sti",
57
- "sxi",
58
- "uop",
59
- "wmf",
60
- "csv",
61
- "dbf",
62
- "dif",
63
- "fods",
64
- "ods",
65
- "ots",
66
- "pxl",
67
- "sdc",
68
- "slk",
69
- "stc",
70
- "sxc",
71
- "uos",
72
- "xls",
73
- "xlt",
74
- "xlsx",
75
- "tif",
76
- "jpeg",
77
- "odp",
2
+ 'bib',
3
+ 'doc',
4
+ 'xml',
5
+ 'docx',
6
+ 'fodt',
7
+ 'html',
8
+ 'ltx',
9
+ 'txt',
10
+ 'odt',
11
+ 'ott',
12
+ 'pdb',
13
+ 'pdf',
14
+ 'psw',
15
+ 'rtf',
16
+ 'sdw',
17
+ 'stw',
18
+ 'sxw',
19
+ 'uot',
20
+ 'vor',
21
+ 'wps',
22
+ 'epub',
23
+ 'png',
24
+ 'bmp',
25
+ 'emf',
26
+ 'eps',
27
+ 'fodg',
28
+ 'gif',
29
+ 'jpg',
30
+ 'met',
31
+ 'odd',
32
+ 'otg',
33
+ 'pbm',
34
+ 'pct',
35
+ 'pgm',
36
+ 'ppm',
37
+ 'ras',
38
+ 'std',
39
+ 'svg',
40
+ 'svm',
41
+ 'swf',
42
+ 'sxd',
43
+ 'sxw',
44
+ 'tiff',
45
+ 'xhtml',
46
+ 'xpm',
47
+ 'fodp',
48
+ 'pages',
49
+ 'potm',
50
+ 'pot',
51
+ 'pptx',
52
+ 'pps',
53
+ 'ppt',
54
+ 'pwp',
55
+ 'sda',
56
+ 'sdd',
57
+ 'sti',
58
+ 'sxi',
59
+ 'uop',
60
+ 'wmf',
61
+ 'csv',
62
+ 'dbf',
63
+ 'dif',
64
+ 'fods',
65
+ 'ods',
66
+ 'ots',
67
+ 'pxl',
68
+ 'sdc',
69
+ 'slk',
70
+ 'stc',
71
+ 'sxc',
72
+ 'uos',
73
+ 'xls',
74
+ 'xlt',
75
+ 'xlsx',
76
+ 'tif',
77
+ 'jpeg',
78
+ 'odp',
79
+ 'odg',
80
+ 'dotx',
81
+ 'xltx'
78
82
  ];
@@ -1,13 +1,13 @@
1
- import {constants, createReadStream, promises, ReadStream} from "fs";
2
- import path from "path";
1
+ import { constants, createReadStream, promises, ReadStream } from 'fs';
2
+ import path from 'path';
3
3
 
4
- import {fromStream, fromBuffer} from "file-type";
4
+ import { fromStream, fromBuffer } from 'file-type';
5
5
 
6
- import FormData from "form-data";
6
+ import FormData from 'form-data';
7
7
 
8
- import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
9
- import {LIBRE_OFFICE_EXTENSIONS} from "./constants";
10
- import {PageProperties} from "../interfaces/libre-office.types";
8
+ import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
9
+ import { LIBRE_OFFICE_EXTENSIONS } from './constants';
10
+ import { PageProperties } from '../interfaces/libre-office.types';
11
11
 
12
12
  /**
13
13
  * Utility class for handling common tasks related to LibreOffice conversions.
@@ -20,7 +20,10 @@ export class LibreOfficeUtils {
20
20
  * @param {FormData} data - The FormData object to which files will be added.
21
21
  * @throws {Error} Throws an error if the file extension is not supported.
22
22
  */
23
- public static async addFiles(files: PathLikeOrReadStream[], data: FormData) {
23
+ public static async addFiles(
24
+ files: PathLikeOrReadStream[],
25
+ data: FormData
26
+ ) {
24
27
  for (const [key, value] of files.entries()) {
25
28
  let file = value;
26
29
  let fileInfo;
@@ -32,18 +35,18 @@ export class LibreOfficeUtils {
32
35
  } else {
33
36
  await promises.access(value, constants.R_OK);
34
37
  const filename = path.basename(value.toString());
35
- fileInfo = {ext: path.extname(filename).slice(1)};
36
- file = createReadStream(value)
38
+ fileInfo = { ext: path.extname(filename).slice(1) };
39
+ file = createReadStream(value);
37
40
  }
38
41
 
39
42
  if (!fileInfo) {
40
- throw new Error("File type could not be determined");
43
+ throw new Error('File type could not be determined');
41
44
  }
42
45
 
43
46
  const extension = fileInfo.ext;
44
47
 
45
48
  if (LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
46
- data.append("files", file, `${key}.${extension}`);
49
+ data.append('files', file, `${key}.${extension}`);
47
50
  } else {
48
51
  throw new Error(`${extension} is not supported`);
49
52
  }
@@ -61,20 +64,20 @@ export class LibreOfficeUtils {
61
64
  pageProperties: PageProperties
62
65
  ): void {
63
66
  if (pageProperties.landscape) {
64
- data.append("landscape", String(pageProperties.landscape));
67
+ data.append('landscape', String(pageProperties.landscape));
65
68
  }
66
69
 
67
70
  if (pageProperties.nativePageRanges) {
68
71
  GotenbergUtils.assert(
69
72
  pageProperties.nativePageRanges.from > 0 &&
70
- pageProperties.nativePageRanges.to > 0 &&
71
- pageProperties.nativePageRanges.to >=
72
- pageProperties.nativePageRanges.from,
73
- "page ranges syntax error"
73
+ pageProperties.nativePageRanges.to > 0 &&
74
+ pageProperties.nativePageRanges.to >=
75
+ pageProperties.nativePageRanges.from,
76
+ 'page ranges syntax error'
74
77
  );
75
78
 
76
79
  data.append(
77
- "nativePageRanges",
80
+ 'nativePageRanges',
78
81
  `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
79
82
  );
80
83
  }
@@ -1,14 +1,14 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import {promises, createReadStream} from "fs";
3
- import {LibreOfficeUtils} from "../libre-office.utils";
2
+ import { promises, createReadStream } from 'fs';
3
+ import { LibreOfficeUtils } from '../libre-office.utils';
4
4
 
5
- import FormData from "form-data";
6
- import FileType from "file-type";
5
+ import FormData from 'form-data';
6
+ import FileType from 'file-type';
7
7
 
8
- describe("LibreOfficeUtils", () => {
9
- const mockPromisesAccess = jest.spyOn(promises, "access");
10
- const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
11
- const mockFromBuffer = jest.spyOn(FileType, "fromBuffer");
8
+ describe('LibreOfficeUtils', () => {
9
+ const mockPromisesAccess = jest.spyOn(promises, 'access');
10
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
11
+ const mockFromBuffer = jest.spyOn(FileType, 'fromBuffer');
12
12
 
13
13
  const data = new FormData();
14
14
 
@@ -22,67 +22,70 @@ describe("LibreOfficeUtils", () => {
22
22
  jest.resetAllMocks();
23
23
  });
24
24
 
25
- describe("addFiles", () => {
26
- describe("when files exist", () => {
27
- describe("when files parameter contains paths", () => {
28
- it("should append each file to data", async () => {
25
+ describe('addFiles', () => {
26
+ describe('when files exist', () => {
27
+ describe('when files parameter contains paths', () => {
28
+ it('should append each file to data', async () => {
29
29
  mockPromisesAccess.mockResolvedValue();
30
30
  await LibreOfficeUtils.addFiles(
31
- ["path/to/file.docx", "path/to/file.bib"],
31
+ ['path/to/file.docx', 'path/to/file.bib'],
32
32
  data
33
33
  );
34
34
  expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
35
35
  });
36
- })
37
- describe("when files parameter contains a buffer", () => {
38
- it("should append each file to data", async () => {
36
+ });
37
+ describe('when files parameter contains a buffer', () => {
38
+ it('should append each file to data', async () => {
39
39
  mockPromisesAccess.mockResolvedValueOnce();
40
40
  mockFromBuffer.mockResolvedValueOnce({
41
- ext: "docx",
42
- mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
43
- })
41
+ ext: 'docx',
42
+ mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
43
+ });
44
44
  await LibreOfficeUtils.addFiles(
45
- [Buffer.from("data"), "path/to/file.bib"],
45
+ [Buffer.from('data'), 'path/to/file.bib'],
46
46
  data
47
47
  );
48
48
  expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
49
49
  });
50
- })
50
+ });
51
51
  });
52
52
 
53
- describe("when one of the files has undetermined format", () => {
54
- it("should throw an error", async () => {
53
+ describe('when one of the files has undetermined format', () => {
54
+ it('should throw an error', async () => {
55
55
  mockPromisesAccess.mockResolvedValueOnce();
56
- mockFromBuffer.mockResolvedValueOnce(undefined
57
- )
56
+ mockFromBuffer.mockResolvedValueOnce(undefined);
58
57
 
59
- await expect(LibreOfficeUtils.addFiles(
60
- [Buffer.from("data"), "path/to/file.bib"],
61
- data
62
- )).rejects.toThrow("File type could not be determined");
58
+ await expect(
59
+ LibreOfficeUtils.addFiles(
60
+ [Buffer.from('data'), 'path/to/file.bib'],
61
+ data
62
+ )
63
+ ).rejects.toThrow('File type could not be determined');
63
64
  });
64
- })
65
+ });
65
66
 
66
- describe("when one of the files has unsupported format", () => {
67
- it("should throw an error", async () => {
67
+ describe('when one of the files has unsupported format', () => {
68
+ it('should throw an error', async () => {
68
69
  mockPromisesAccess.mockResolvedValueOnce();
69
70
  await expect(() =>
70
71
  LibreOfficeUtils.addFiles(
71
- ["path/to/file.rar", "path/to/file.pdf"],
72
+ ['path/to/file.rar', 'path/to/file.pdf'],
72
73
  data
73
74
  )
74
- ).rejects.toThrow("rar is not supported");
75
+ ).rejects.toThrow('rar is not supported');
75
76
  });
76
77
  });
77
78
 
78
- describe("when one of the files does not exist", () => {
79
- it("should throw an error", async () => {
79
+ describe('when one of the files does not exist', () => {
80
+ it('should throw an error', async () => {
80
81
  const errorMessage =
81
82
  "ENOENT: no such file or directory, access 'path/to/index.html'";
82
- mockPromisesAccess.mockRejectedValueOnce(new Error(errorMessage));
83
+ mockPromisesAccess.mockRejectedValueOnce(
84
+ new Error(errorMessage)
85
+ );
83
86
  await expect(() =>
84
87
  LibreOfficeUtils.addFiles(
85
- ["path/to/file.pdf", "path/to/another-file.pdf"],
88
+ ['path/to/file.pdf', 'path/to/another-file.pdf'],
86
89
  data
87
90
  )
88
91
  ).rejects.toThrow(errorMessage);
@@ -90,27 +93,33 @@ describe("LibreOfficeUtils", () => {
90
93
  });
91
94
  });
92
95
 
93
- describe("addPageProperties", () => {
94
- describe("Page landscape", () => {
95
- describe("when landscape parameter is set", () => {
96
- it("should append landscape to data", () => {
96
+ describe('addPageProperties', () => {
97
+ describe('Page landscape', () => {
98
+ describe('when landscape parameter is set', () => {
99
+ it('should append landscape to data', () => {
97
100
  LibreOfficeUtils.addPageProperties(data, {
98
- landscape: true,
101
+ landscape: true
99
102
  });
100
103
  expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
101
- expect(data.append).toHaveBeenCalledWith("landscape", "true");
104
+ expect(data.append).toHaveBeenCalledWith(
105
+ 'landscape',
106
+ 'true'
107
+ );
102
108
  });
103
109
  });
104
110
  });
105
111
 
106
- describe("Page ranges", () => {
107
- describe("when nativePageRanges is valid", () => {
108
- it("should append nativePageRanges to data", () => {
112
+ describe('Page ranges', () => {
113
+ describe('when nativePageRanges is valid', () => {
114
+ it('should append nativePageRanges to data', () => {
109
115
  LibreOfficeUtils.addPageProperties(data, {
110
- nativePageRanges: {from: 1, to: 6},
116
+ nativePageRanges: { from: 1, to: 6 }
111
117
  });
112
118
  expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
113
- expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
119
+ expect(data.append).toHaveBeenCalledWith(
120
+ 'nativePageRanges',
121
+ '1-6'
122
+ );
114
123
  });
115
124
  });
116
125
  });