From a8872a27a53274c3fc51403b4b0d08db63bbcf46 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 09:20:45 +0100 Subject: [PATCH 01/11] ci(cd): sort release note sections alphabetically Also use folded block for changelog-types param and add tests to changelog --- .github/workflows/cd.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5a9e9ef7..47b771d8 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -25,7 +25,19 @@ jobs: # Staying on v3 due to incomplete migration guide for v4 uses: google-github-actions/release-please-action@v3 with: - changelog-types: '[ { "type": "feat", "section": "Features", "hidden": false }, { "type": "fix", "section": "Bug fixes", "hidden": false }, { "type": "build", "section": "Dependencies", "hidden": false }, { "type": "chore", "section": "Miscellaneous", "hidden": false }, { "type": "ci", "section": "Continuous integration", "hidden": false }, { "type": "perf", "section": "Improvements", "hidden": false }, { "type": "refactor", "section": "Improvements", "hidden": false }, { "type": "style", "section": "Miscellaneous", "hidden": false }, { "type": "docs", "section": "Documentation", "hidden": false }]' + changelog-types: > + [ + { "section": "Bug fixes", "type": "fix", "hidden": false }, + { "section": "Continuous integration", "type": "ci", "hidden": false }, + { "section": "Dependencies", "type": "build", "hidden": false }, + { "section": "Documentation", "type": "docs", "hidden": false }, + { "section": "Features", "type": "feat", "hidden": false }, + { "section": "Improvements", "type": "perf", "hidden": false }, + { "section": "Improvements", "type": "refactor", "hidden": false }, + { "section": "Miscellaneous", "type": "chore", "hidden": false }, + { "section": "Miscellaneous", "type": "style", "hidden": false }, + { "section": "Tests", "type": "test", "hidden": false } + ] release-type: node package-name: node-poppler From 0423f52f381136a3c50cf4c47eb02a03098763b6 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 09:54:49 +0100 Subject: [PATCH 02/11] build(deps): bump semver from 7.6.0 to 7.6.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72f33b64..ff8e9e47 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ }, "dependencies": { "camelcase": "^6.3.0", - "semver": "^7.6.0", + "semver": "^7.6.3", "upath": "^2.0.1" } } From 18f30da738ca74194c02d2bb081b87febd99938b Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:06:56 +0100 Subject: [PATCH 03/11] build(deps-dev): bump dev dependencies --- package.json | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index ff8e9e47..bfd129a8 100644 --- a/package.json +++ b/package.json @@ -86,26 +86,27 @@ "testTimeout": 60000 }, "devDependencies": { - "@commitlint/cli": "^19.1.0", - "@commitlint/config-conventional": "^19.1.0", - "@eslint-community/eslint-plugin-eslint-comments": "^4.1.0", + "@commitlint/cli": "^19.3.0", + "@commitlint/config-conventional": "^19.2.2", + "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0", "@types/jest": "^29.5.12", + "@types/semver": "^7.5.8", "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-jest": "^27.9.0", - "eslint-plugin-jsdoc": "^48.2.1", - "eslint-plugin-promise": "^6.1.1", - "eslint-plugin-regexp": "^2.3.0", - "eslint-plugin-security": "^2.1.1", + "eslint-plugin-jest": "^28.6.0", + "eslint-plugin-jsdoc": "^48.9.1", + "eslint-plugin-promise": "^7.0.0", + "eslint-plugin-regexp": "^2.6.0", + "eslint-plugin-security": "^3.0.1", "glob": "^10.3.10", - "husky": "^9.0.11", + "husky": "^9.1.3", "jest": "^29.7.0", "license-checker": "^25.0.1", - "prettier": "^3.2.5", + "prettier": "^3.3.3", "spdx-copyleft": "^1.0.0", - "typescript": "^5.4.2" + "typescript": "^5.5.4" }, "dependencies": { "camelcase": "^6.3.0", From e96b0cce97caa12008ed9e3b62b17a1203994b5e Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:15:56 +0100 Subject: [PATCH 04/11] chore(package): use shorter semver syntax --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfd129a8..aab45409 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "author": "Frazer Smith ", "funding": "https://github.com/sponsors/Fdawgs", "engines": { - "node": ">=18.0.0" + "node": ">=18" }, "scripts": { "build": "tsc", From 21d6cccf14bed79af18e49550b0a2e6c75403769 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:35:31 +0100 Subject: [PATCH 05/11] chore(tsconfig): update target to `ES2023` --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index e73e3c39..4f63f64e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "moduleResolution": "NodeNext", "outDir": "types", "resolveJsonModule": true, - "target": "ES2022" + "target": "ES2023" }, "include": ["src/index.js"] } From 8bee3691db0b9f45ec7dcd0b64b486de38adcced Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:36:50 +0100 Subject: [PATCH 06/11] chore(.husky/commit-msg): remove `npx` usage --- .husky/commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index d468455f..70698824 100644 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1 +1 @@ -npx --no-install commitlint --edit $1 \ No newline at end of file +commitlint --edit $1 \ No newline at end of file From 56661cc9bdfb802633669eab3f70f4cfee69f858 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:42:44 +0100 Subject: [PATCH 07/11] ci(ci): add node 22 to test matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b163fcf2..a93a2911 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: if: github.event.pull_request.draft == false strategy: matrix: - node-version: [18, 20] + node-version: [18, 20, 22] os: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: From 73798178c1c92a7829efaf57e7c1e0186ea236d4 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 10:58:34 +0100 Subject: [PATCH 08/11] test(index): account for arm macs --- src/index.test.js | 53 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index 26e5266b..de41a84e 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -4,12 +4,12 @@ "use strict"; -const { execFile } = require("node:child_process"); +const { execFile, spawnSync } = require("node:child_process"); const { access, readFile, unlink } = require("node:fs/promises"); const { promisify } = require("node:util"); const { glob } = require("glob"); const { lt } = require("semver"); -const { joinSafe } = require("upath"); +const { joinSafe, normalizeTrim } = require("upath"); const execFileAsync = promisify(execFile); const { Poppler } = require("./index"); @@ -17,32 +17,33 @@ const { Poppler } = require("./index"); const testDirectory = `${__dirname}/../test_resources/test_files/`; const file = `${testDirectory}pdf_1.3_NHS_Constitution.pdf`; -const windowsPath = joinSafe( - __dirname, - "lib", - "win32", - "poppler-24.02.0", - "Library", - "bin" -); -let testBinaryPath; -switch (process.platform) { - // macOS - case "darwin": - testBinaryPath = "/usr/local/bin"; - break; - - case "linux": - testBinaryPath = "/usr/bin"; - break; - - // Windows OS - case "win32": - default: - testBinaryPath = windowsPath; - break; +/** + * @description Returns the path to the poppler-util binaries based on the OS. + * @returns {string} The path to the poppler-util binaries. + */ +function getTestBinaryPath() { + const { platform } = process; + const which = spawnSync(platform === "win32" ? "where" : "which", [ + "pdfinfo", + ]).stdout.toString(); + let popplerPath = /(.+)pdfinfo/u.exec(which)?.[1]; + + if (platform === "win32" && !popplerPath) { + popplerPath = joinSafe( + __dirname, + "lib", + "win32", + "poppler-24.02.0", + "Library", + "bin" + ); + } + + return normalizeTrim(popplerPath); } +const testBinaryPath = getTestBinaryPath(); + describe("Node-Poppler module", () => { afterEach(async () => { // Remove leftover test files From eeaf62274215e68db927ecf772ed1a8d32cf4b87 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 18:02:17 +0100 Subject: [PATCH 09/11] ci(ci): run `apt-get update` for ubuntu tests --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a93a2911..ea83abf3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,7 +127,9 @@ jobs: - name: Install Ubuntu dependencies if: matrix.os == 'ubuntu-latest' - run: sudo apt-get -y install poppler-data poppler-utils + run: | + sudo apt-get -q update + sudo apt-get -y install poppler-data poppler-utils - name: Run tests run: npm run jest:coverage From 6e1da095bbf1a32ab722193645b187775c3c9ef3 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 18:11:01 +0100 Subject: [PATCH 10/11] ci(ci): ignore recommended packages --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea83abf3..5042b2bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: if: matrix.os == 'ubuntu-latest' run: | sudo apt-get -q update - sudo apt-get -y install poppler-data poppler-utils + sudo apt-get -y --no-install-recommends install poppler-data poppler-utils - name: Run tests run: npm run jest:coverage From 435a5e7f3c962efadaf056180bd944191b663eb1 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 29 Jul 2024 18:36:53 +0100 Subject: [PATCH 11/11] test(index): fix skipped test --- src/index.test.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index de41a84e..af5b7e0a 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -67,6 +67,10 @@ describe("Node-Poppler module", () => { ({ platform } = process); }); + beforeEach(() => { + jest.resetModules(); + }); + afterEach(() => { // Restore the process platform Object.defineProperty(process, "platform", { @@ -79,19 +83,13 @@ describe("Node-Poppler module", () => { expect(poppler.popplerPath).toBe(testBinaryPath); }); - /** - * @todo Fix this test, mocking of "node:" scheme not supported yet. - * @see {@link https://github.com/jestjs/jest/pull/14297 | Jest PR #14297} - */ - // eslint-disable-next-line jest/no-disabled-tests -- Blocked by Jest PR #14297 - it.skip("Throws an Error if the binary path is not found", () => { + it("Throws an Error if the binary path is not found", () => { Object.defineProperty(process, "platform", { value: "mockOS", }); - // Ensure the mock is used by the UnRTF constructor - jest.resetModules(); - jest.mock("node:child_process", () => ({ + jest.doMock("node:child_process", () => ({ + ...jest.requireActual("node:child_process"), spawnSync: jest.fn(() => ({ stdout: { toString: () => "",