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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b163fcf2..5042b2bc 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: @@ -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 --no-install-recommends install poppler-data poppler-utils - name: Run tests run: npm run jest:coverage 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 diff --git a/package.json b/package.json index 72f33b64..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", @@ -86,30 +86,31 @@ "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", - "semver": "^7.6.0", + "semver": "^7.6.3", "upath": "^2.0.1" } } diff --git a/src/index.test.js b/src/index.test.js index 26e5266b..af5b7e0a 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 @@ -66,6 +67,10 @@ describe("Node-Poppler module", () => { ({ platform } = process); }); + beforeEach(() => { + jest.resetModules(); + }); + afterEach(() => { // Restore the process platform Object.defineProperty(process, "platform", { @@ -78,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: () => "", 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"] }