diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..6982e861 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "name": "vscode-jest-tests.v2", + "request": "launch", + "args": [ + "--runInBand", + "--watchAll=false", + "--testNamePattern", + "${jest.testNamePattern}", + "--runTestsByPath", + "${jest.testFile}", + "--config", + "${workspaceFolder}/jest.config.ts" + ], + "env": { + "NODE_OPTIONS": "--experimental-vm-modules" + }, + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + } + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4be27d7b..01bc6198 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1014,9 +1014,9 @@ } }, "node_modules/@commitlint/load/node_modules/@types/node": { - "version": "18.18.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.7.tgz", - "integrity": "sha512-bw+lEsxis6eqJYW8Ql6+yTqkE6RuFtsQPSe5JxXbqYRFQEER5aJA9a5UH9igqDWm3X4iLHIKOHlnAXLM4mi7uQ==", + "version": "18.18.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.8.tgz", + "integrity": "sha512-OLGBaaK5V3VRBS1bAkMVP2/W9B+H8meUfl866OrMNQqt7wDgdpWPp5o6gmIc9pB+lIQHSq4ZL8ypeH1vPxcPaQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -2644,13 +2644,13 @@ } }, "node_modules/@ridedott/eslint-plugin": { - "version": "1.7.136", - "resolved": "https://registry.npmjs.org/@ridedott/eslint-plugin/-/eslint-plugin-1.7.136.tgz", - "integrity": "sha512-jnuipSxyiH9N2ZGkWXsaIiP7D9hUP1tG2VrUNjffb35U5hqVwN5vLc7QhfotWlsB5Pc8GL1H32bBLhffvnoK9g==", + "version": "1.7.137", + "resolved": "https://registry.npmjs.org/@ridedott/eslint-plugin/-/eslint-plugin-1.7.137.tgz", + "integrity": "sha512-xN+KH1NaXeZ26bzkrK+b5qUQVtPjFM6W5rM3MCdCjjovMvtVayD3zLLpdNaiKpk8bYMpYr9tET8lGu5sR/hasg==", "dev": true, "dependencies": { - "@typescript-eslint/parser": "^6.9.0", - "@typescript-eslint/utils": "^6.9.0" + "@typescript-eslint/parser": "^6.9.1", + "@typescript-eslint/utils": "^6.9.1" }, "engines": { "node": ">=18" @@ -3588,9 +3588,9 @@ } }, "node_modules/@types/jest": { - "version": "29.5.6", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.6.tgz", - "integrity": "sha512-/t9NnzkOpXb4Nfvg17ieHE6EeSjDS2SGSpNYfoLbUAeL/EOueU/RSdOWFpfQTXBEM7BguYW1XQ0EbM+6RlIh6w==", + "version": "29.5.7", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.7.tgz", + "integrity": "sha512-HLyetab6KVPSiF+7pFcUyMeLsx25LDNDemw9mGsJBkai/oouwrjTycocSDYopMEwFhN2Y4s9oPyOCZNofgSt2g==", "dev": true, "dependencies": { "expect": "^29.0.0", @@ -3622,9 +3622,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.9.tgz", - "integrity": "sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==", + "version": "20.8.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.10.tgz", + "integrity": "sha512-TlgT8JntpcbmKUFzjhsyhGfP2fsiz1Mv56im6enJ905xG1DAYesxJaeSbGqQmAw8OWPdhyJGhGSQGKRNJ45u9w==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -3681,16 +3681,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.9.0.tgz", - "integrity": "sha512-lgX7F0azQwRPB7t7WAyeHWVfW1YJ9NIgd9mvGhfQpRY56X6AVf8mwM8Wol+0z4liE7XX3QOt8MN1rUKCfSjRIA==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.9.1.tgz", + "integrity": "sha512-w0tiiRc9I4S5XSXXrMHOWgHgxbrBn1Ro+PmiYhSg2ZVdxrAJtQgzU5o2m1BfP6UOn7Vxcc6152vFjQfmZR4xEg==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.9.0", - "@typescript-eslint/type-utils": "6.9.0", - "@typescript-eslint/utils": "6.9.0", - "@typescript-eslint/visitor-keys": "6.9.0", + "@typescript-eslint/scope-manager": "6.9.1", + "@typescript-eslint/type-utils": "6.9.1", + "@typescript-eslint/utils": "6.9.1", + "@typescript-eslint/visitor-keys": "6.9.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -3716,15 +3716,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.9.0.tgz", - "integrity": "sha512-GZmjMh4AJ/5gaH4XF2eXA8tMnHWP+Pm1mjQR2QN4Iz+j/zO04b9TOvJYOX2sCNIQHtRStKTxRY1FX7LhpJT4Gw==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.9.1.tgz", + "integrity": "sha512-C7AK2wn43GSaCUZ9do6Ksgi2g3mwFkMO3Cis96kzmgudoVaKyt62yNzJOktP0HDLb/iO2O0n2lBOzJgr6Q/cyg==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.9.0", - "@typescript-eslint/types": "6.9.0", - "@typescript-eslint/typescript-estree": "6.9.0", - "@typescript-eslint/visitor-keys": "6.9.0", + "@typescript-eslint/scope-manager": "6.9.1", + "@typescript-eslint/types": "6.9.1", + "@typescript-eslint/typescript-estree": "6.9.1", + "@typescript-eslint/visitor-keys": "6.9.1", "debug": "^4.3.4" }, "engines": { @@ -3744,13 +3744,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.9.0.tgz", - "integrity": "sha512-1R8A9Mc39n4pCCz9o79qRO31HGNDvC7UhPhv26TovDsWPBDx+Sg3rOZdCELIA3ZmNoWAuxaMOT7aWtGRSYkQxw==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.9.1.tgz", + "integrity": "sha512-38IxvKB6NAne3g/+MyXMs2Cda/Sz+CEpmm+KLGEM8hx/CvnSRuw51i8ukfwB/B/sESdeTGet1NH1Wj7I0YXswg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.9.0", - "@typescript-eslint/visitor-keys": "6.9.0" + "@typescript-eslint/types": "6.9.1", + "@typescript-eslint/visitor-keys": "6.9.1" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -3761,13 +3761,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.9.0.tgz", - "integrity": "sha512-XXeahmfbpuhVbhSOROIzJ+b13krFmgtc4GlEuu1WBT+RpyGPIA4Y/eGnXzjbDj5gZLzpAXO/sj+IF/x2GtTMjQ==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.9.1.tgz", + "integrity": "sha512-eh2oHaUKCK58qIeYp19F5V5TbpM52680sB4zNSz29VBQPTWIlE/hCj5P5B1AChxECe/fmZlspAWFuRniep1Skg==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.9.0", - "@typescript-eslint/utils": "6.9.0", + "@typescript-eslint/typescript-estree": "6.9.1", + "@typescript-eslint/utils": "6.9.1", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -3788,9 +3788,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.9.0.tgz", - "integrity": "sha512-+KB0lbkpxBkBSiVCuQvduqMJy+I1FyDbdwSpM3IoBS7APl4Bu15lStPjgBIdykdRqQNYqYNMa8Kuidax6phaEw==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.9.1.tgz", + "integrity": "sha512-BUGslGOb14zUHOUmDB2FfT6SI1CcZEJYfF3qFwBeUrU6srJfzANonwRYHDpLBuzbq3HaoF2XL2hcr01c8f8OaQ==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -3801,13 +3801,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.9.0.tgz", - "integrity": "sha512-NJM2BnJFZBEAbCfBP00zONKXvMqihZCrmwCaik0UhLr0vAgb6oguXxLX1k00oQyD+vZZ+CJn3kocvv2yxm4awQ==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.9.1.tgz", + "integrity": "sha512-U+mUylTHfcqeO7mLWVQ5W/tMLXqVpRv61wm9ZtfE5egz7gtnmqVIw9ryh0mgIlkKk9rZLY3UHygsBSdB9/ftyw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.9.0", - "@typescript-eslint/visitor-keys": "6.9.0", + "@typescript-eslint/types": "6.9.1", + "@typescript-eslint/visitor-keys": "6.9.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -3857,17 +3857,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.9.0.tgz", - "integrity": "sha512-5Wf+Jsqya7WcCO8me504FBigeQKVLAMPmUzYgDbWchINNh1KJbxCgVya3EQ2MjvJMVeXl3pofRmprqX6mfQkjQ==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.9.1.tgz", + "integrity": "sha512-L1T0A5nFdQrMVunpZgzqPL6y2wVreSyHhKGZryS6jrEN7bD9NplVAyMryUhXsQ4TWLnZmxc2ekar/lSGIlprCA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.9.0", - "@typescript-eslint/types": "6.9.0", - "@typescript-eslint/typescript-estree": "6.9.0", + "@typescript-eslint/scope-manager": "6.9.1", + "@typescript-eslint/types": "6.9.1", + "@typescript-eslint/typescript-estree": "6.9.1", "semver": "^7.5.4" }, "engines": { @@ -3882,12 +3882,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.9.0.tgz", - "integrity": "sha512-dGtAfqjV6RFOtIP8I0B4ZTBRrlTT8NHHlZZSchQx3qReaoDeXhYM++M4So2AgFK9ZB0emRPA6JI1HkafzA2Ibg==", + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.9.1.tgz", + "integrity": "sha512-MUaPUe/QRLEffARsmNfmpghuQkW436DvESW+h+M52w0coICHRfD6Np9/K6PdACwnrq1HmuLl+cSPZaJmeVPkSw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.9.0", + "@typescript-eslint/types": "6.9.1", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -4586,9 +4586,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001558", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001558.tgz", - "integrity": "sha512-/Et7DwLqpjS47JPEcz6VnxU9PwcIdVi0ciLXRWBQdj1XFye68pSQYpV0QtPTfUKWuOaEig+/Vez2l74eDc1tPQ==", + "version": "1.0.30001559", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001559.tgz", + "integrity": "sha512-cPiMKZgqgkg5LY3/ntGeLFUpi6tzddBNS58A4tnTgQw1zON7u2sZMU7SzOeVH4tj20++9ggL+V6FDOFMTaFFYA==", "dev": true, "funding": [ { @@ -5906,9 +5906,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.569", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.569.tgz", - "integrity": "sha512-LsrJjZ0IbVy12ApW3gpYpcmHS3iRxH4bkKOW98y1/D+3cvDUWGcbzbsFinfUS8knpcZk/PG/2p/RnkMCYN7PVg==", + "version": "1.4.571", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.571.tgz", + "integrity": "sha512-Sc+VtKwKCDj3f/kLBjdyjMpNzoZsU6WuL/wFb6EH8USmHEcebxRXcRrVpOpayxd52tuey4RUDpUsw5OS5LhJqg==", "dev": true }, "node_modules/emittery": { @@ -9449,9 +9449,9 @@ } }, "node_modules/jiti": { - "version": "1.20.0", - "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.20.0.tgz", - "integrity": "sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==", + "version": "1.21.0", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", + "integrity": "sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==", "dev": true, "bin": { "jiti": "bin/jiti.js" @@ -10127,9 +10127,9 @@ } }, "node_modules/marked": { - "version": "9.1.3", - "resolved": "https://registry.npmjs.org/marked/-/marked-9.1.3.tgz", - "integrity": "sha512-XPU/J7GzU/n4voCSw1VYggtr3W5C2OeGkwEbe5PIQdA8thaie2Qw+fig6iNidKNDokTNcyR4OE9fMK14P6rqPg==", + "version": "9.1.4", + "resolved": "https://registry.npmjs.org/marked/-/marked-9.1.4.tgz", + "integrity": "sha512-Mq83CCaClhXqhf8sLQ57c1unNelHEuFadK36ga+GeXR4FeT/5ssaC5PaCRVqMA74VYorzYRqdAaxxteIanh3Kw==", "bin": { "marked": "bin/marked.js" }, @@ -14392,9 +14392,9 @@ "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==" }, "node_modules/punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true, "engines": { "node": ">=6" @@ -15033,9 +15033,9 @@ "dev": true }, "node_modules/semantic-release": { - "version": "22.0.5", - "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-22.0.5.tgz", - "integrity": "sha512-ESCEQsZlBj1DWMA84RthaJzQHHnihoGk49s9nUxHfRNUNZelLE9JZrE94bHO2Y00EWb7iwrzr1OYhv5QNVmf8A==", + "version": "22.0.6", + "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-22.0.6.tgz", + "integrity": "sha512-SxgpGR6b52gaKrb42nnaZWa2h5ig06XlloS3NjUN4W/lRBB8SId4JMaZaxN6Ncb+Ii2Uxd8WO6uvshTSSf8XRg==", "dependencies": { "@semantic-release/commit-analyzer": "^11.0.0", "@semantic-release/error": "^4.0.0", @@ -15047,7 +15047,7 @@ "debug": "^4.0.0", "env-ci": "^10.0.0", "execa": "^8.0.0", - "figures": "^5.0.0", + "figures": "^6.0.0", "find-versions": "^5.1.0", "get-stream": "^6.0.0", "git-log-parser": "^1.2.0", @@ -15122,15 +15122,14 @@ } }, "node_modules/semantic-release/node_modules/figures": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-5.0.0.tgz", - "integrity": "sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/figures/-/figures-6.0.1.tgz", + "integrity": "sha512-0oY/olScYD4IhQ8u//gCPA4F3mlTn2dacYmiDm/mbDQvpmLjV4uH+zhsQ5IyXRyvqkvtUkXkNdGvg5OFJTCsuQ==", "dependencies": { - "escape-string-regexp": "^5.0.0", - "is-unicode-supported": "^1.2.0" + "is-unicode-supported": "^2.0.0" }, "engines": { - "node": ">=14" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -15159,11 +15158,11 @@ } }, "node_modules/semantic-release/node_modules/is-unicode-supported": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", - "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", + "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", "engines": { - "node": ">=12" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" diff --git a/src/utilities/constants.ts b/src/utilities/constants.ts deleted file mode 100644 index 76009072..00000000 --- a/src/utilities/constants.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -/* eslint-disable no-underscore-dangle */ -import * as url from 'url'; - -export const __filename = url.fileURLToPath(import.meta.url); -export const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); diff --git a/src/utilities/inputProcessors.spec.ts b/src/utilities/inputProcessors.spec.ts index 08a798bd..91f0f9cd 100644 --- a/src/utilities/inputProcessors.spec.ts +++ b/src/utilities/inputProcessors.spec.ts @@ -1,23 +1,19 @@ -import * as actionsCore from '@actions/core'; - -import { - processInputAdditionalPlugins, - processInputCommitAssets, - processInputConfigFile, - processInputDisableChangelog, - processInputDryRun, - processInputNodeModule, - processInputReleaseAssets, - processInputReleaseBranches, - processInputReleaseRules, -} from './inputProcessors.js'; - -const getInputSpy = jest.spyOn(actionsCore, 'getInput').mockImplementation(); +import { jest } from '@jest/globals'; + +const getInputSpy = jest.fn() as unknown as jest.SpiedFunction< + (_: never, packages: string[]) => unknown +>; + +jest.unstable_mockModule('@actions/core', (): unknown => ({ + getInput: getInputSpy, +})); describe('processInputNodeModule', (): void => { - it("returns true when the value of the npm-package input is set to 'true'", (): void => { + it("reurns true when the value of the npm-package input is set to 'true'", async (): Promise => { expect.assertions(1); + const { processInputNodeModule } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue('true'); const result = processInputNodeModule(); @@ -27,9 +23,13 @@ describe('processInputNodeModule', (): void => { }); describe('processInputDisableGenerateChangelog', (): void => { - it("returns true when the value of the disable-generate-changelog input is set to 'true'", (): void => { + it("returns true when the value of the disable-generate-changelog input is set to 'true'", async (): Promise => { expect.assertions(1); + const { processInputDisableChangelog } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue('true'); const result = processInputDisableChangelog(); @@ -39,9 +39,11 @@ describe('processInputDisableGenerateChangelog', (): void => { }); describe('processInputDryRun', (): void => { - it("returns true when the value of the dry-run input is set to 'true'", (): void => { + it("returns true when the value of the dry-run input is set to 'true'", async (): Promise => { expect.assertions(1); + const { processInputDryRun } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue('true'); const result = processInputDryRun(); @@ -51,9 +53,13 @@ describe('processInputDryRun', (): void => { }); describe('processInputReleaseBranches', (): void => { - it('throws an error if the input parameter value is set to an invalid JSON string', (): void => { + it('throws an error if the input parameter value is set to an invalid JSON string', async (): Promise => { expect.assertions(1); + const { processInputReleaseBranches } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue('test'); expect(processInputReleaseBranches).toThrow( @@ -85,9 +91,13 @@ describe('processInputReleaseBranches', (): void => { }, ])( 'throws an error if the input parameter is set to an invalid value %j', - ({ value }: { value: string }): void => { + async ({ value }: { value: string }): Promise => { expect.assertions(1); + const { processInputReleaseBranches } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue(value); try { @@ -98,9 +108,13 @@ describe('processInputReleaseBranches', (): void => { }, ); - it("returns undefined if the input parameter value is set to an empty string''", (): void => { + it("returns undefined if the input parameter value is set to an empty string''", async (): Promise => { expect.assertions(1); + const { processInputReleaseBranches } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue(''); const result = processInputReleaseBranches(); @@ -108,9 +122,12 @@ describe('processInputReleaseBranches', (): void => { expect(result).toBeUndefined(); }); - it('returns a valid branches configuration array passed as json-string', (): void => { + it('returns a valid branches configuration array passed as json-string', async (): Promise => { expect.assertions(1); + const { processInputReleaseBranches } = await import( + './inputProcessors.js' + ); getInputSpy.mockReturnValue( JSON.stringify([ '+([0-9])?(.{+([0-9]),x}).x', @@ -136,9 +153,11 @@ describe('processInputReleaseBranches', (): void => { }); describe('processInputReleaseRules', (): void => { - it('throws an error if the input parameter value is set to an invalid JSON string', (): void => { + it('throws an error if the input parameter value is set to an invalid JSON string', async (): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce('test').mockReturnValueOnce(''); expect(processInputReleaseRules).toThrow( @@ -167,9 +186,11 @@ describe('processInputReleaseRules', (): void => { }, ])( 'throws an error if the input parameter is set to an invalid value %j', - ({ value }: { value: string }): void => { + async ({ value }: { value: string }): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce(value).mockReturnValueOnce(''); /* eslint-disable-next-line jest/require-to-throw-message */ @@ -177,9 +198,11 @@ describe('processInputReleaseRules', (): void => { }, ); - it("returns the default release rules if the input parameter value is set to an empty string''", (): void => { + it("returns the default release rules if the input parameter value is set to an empty string''", async (): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce('').mockReturnValueOnce(''); const result = processInputReleaseRules(); @@ -195,9 +218,11 @@ describe('processInputReleaseRules', (): void => { ]); }); - it('returns a valid branches configuration array passed as json-string', (): void => { + it('returns a valid branches configuration array passed as json-string', async (): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy .mockReturnValueOnce( JSON.stringify([ @@ -219,9 +244,11 @@ describe('processInputReleaseRules', (): void => { }); describe('processInputReleaseRulesAppend', (): void => { - it('throws an error if the release-rules-append input parameter value is set to an invalid JSON string', (): void => { + it('throws an error if the release-rules-append input parameter value is set to an invalid JSON string', async (): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce('').mockReturnValueOnce('test'); expect(processInputReleaseRules).toThrow( @@ -250,9 +277,11 @@ describe('processInputReleaseRulesAppend', (): void => { }, ])( 'throws an error if the release-rules-append input parameter is set to an invalid value %j', - ({ value }: { value: string }): void => { + async ({ value }: { value: string }): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce('').mockReturnValueOnce(value); /* eslint-disable-next-line jest/require-to-throw-message */ @@ -260,8 +289,11 @@ describe('processInputReleaseRulesAppend', (): void => { }, ); - it('throws and error when both release-rules and release-rules-append are defined', (): void => { + it('throws and error when both release-rules and release-rules-append are defined', async (): Promise => { expect.assertions(1); + + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy .mockReturnValueOnce( JSON.stringify([ @@ -278,9 +310,11 @@ describe('processInputReleaseRulesAppend', (): void => { ); }); - it('returns default release rules with append rules added to the end', (): void => { + it('returns default release rules with append rules added to the end', async (): Promise => { expect.assertions(1); + const { processInputReleaseRules } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValueOnce('').mockReturnValueOnce( JSON.stringify([ { @@ -315,9 +349,11 @@ describe('processInputReleaseRulesAppend', (): void => { }); describe('processInputCommitAssets', (): void => { - it('returns an array of valid paths relative to the project root', (): void => { + it('returns an array of valid paths relative to the project root', async (): Promise => { expect.assertions(1); + const { processInputCommitAssets } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue(` ./src `); @@ -329,9 +365,11 @@ describe('processInputCommitAssets', (): void => { }); describe('processInputReleaseAssets', (): void => { - it('returns an array of valid paths relative to the project root', (): void => { + it('returns an array of valid paths relative to the project root', async (): Promise => { expect.assertions(1); + const { processInputReleaseAssets } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue(` ./src `); @@ -343,9 +381,11 @@ describe('processInputReleaseAssets', (): void => { }); describe('processInputConfigFile', (): void => { - it('returns a valid path relative to the project root', (): void => { + it('returns a valid path relative to the project root', async (): Promise => { expect.assertions(1); + const { processInputConfigFile } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue('./src.yaml'); const result = processInputConfigFile(); @@ -353,9 +393,11 @@ describe('processInputConfigFile', (): void => { expect(result).toBe('./src.yaml'); }); - it('throws if the provided path is not a YAML file', (): void => { + it('throws if the provided path is not a YAML file', async (): Promise => { expect.assertions(1); + const { processInputConfigFile } = await import('./inputProcessors.js'); + getInputSpy.mockReturnValue('./src.json'); try { @@ -367,9 +409,13 @@ describe('processInputConfigFile', (): void => { }); describe('processInputAdditionalPlugins', (): void => { - it('returns an object in package.json format', (): void => { + it('returns an object in package.json format', async (): Promise => { expect.assertions(1); + const { processInputAdditionalPlugins } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue( '{"@google/semantic-release-replace-plugin":"^4.0.2"}', ); @@ -381,9 +427,13 @@ describe('processInputAdditionalPlugins', (): void => { }); }); - it('throws if the input is not valid JSON', (): void => { + it('throws if the input is not valid JSON', async (): Promise => { expect.assertions(1); + const { processInputAdditionalPlugins } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue('foo'); try { @@ -393,9 +443,13 @@ describe('processInputAdditionalPlugins', (): void => { } }); - it('throws if the object is not in package.json format', (): void => { + it('throws if the object is not in package.json format', async (): Promise => { expect.assertions(1); + const { processInputAdditionalPlugins } = await import( + './inputProcessors.js' + ); + getInputSpy.mockReturnValue('{"foo":1}'); try { diff --git a/src/utilities/installDependencies.spec.ts b/src/utilities/installDependencies.spec.ts index 2754bee8..3a58b9d0 100644 --- a/src/utilities/installDependencies.spec.ts +++ b/src/utilities/installDependencies.spec.ts @@ -1,9 +1,7 @@ import { jest } from '@jest/globals'; -import { installDependencies } from './installDependencies.js'; - const execSpy = jest.fn() as unknown as jest.SpiedFunction< - typeof import('@actions/exec').exec + (_: never, packages: string[]) => unknown >; jest.unstable_mockModule('@actions/exec', (): unknown => ({ @@ -14,6 +12,8 @@ describe('installDependencies', (): void => { it('executes the install-dependencies script', async (): Promise => { expect.assertions(1); + const { installDependencies } = await import('./installDependencies.js'); + await installDependencies(); expect(execSpy).toHaveBeenCalledTimes(1); @@ -22,12 +22,14 @@ describe('installDependencies', (): void => { it('calls the install-dependencies script with additional packages', async (): Promise => { expect.assertions(1); + const { installDependencies } = await import('./installDependencies.js'); + await installDependencies({ '@semantic-release/git': '^4.0.2', '@semantic-release/test': '^5.0.2', }); - expect(execSpy.mock.calls[0][1]?.slice(1)).toMatchInlineSnapshot(` + expect(execSpy.mock.calls[0][1].slice(1)).toMatchInlineSnapshot(` [ "@semantic-release/git@^4.0.2", "@semantic-release/test@^5.0.2", diff --git a/src/utilities/installDependencies.ts b/src/utilities/installDependencies.ts index 12c637a3..b3d9717c 100644 --- a/src/utilities/installDependencies.ts +++ b/src/utilities/installDependencies.ts @@ -1,9 +1,13 @@ import { exec } from '@actions/exec'; import { resolve as pathResolve } from 'path'; +import * as url from 'url'; -import { __dirname } from './constants.js'; import { AdditionalPluginsSpec } from './inputProcessors.js'; +// eslint-disable-next-line max-len +// eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); + export const installDependencies = async ( additionalPlugins?: AdditionalPluginsSpec, ): Promise => { diff --git a/src/utilities/outputParsers.spec.ts b/src/utilities/outputParsers.spec.ts index d64f6b1a..a46543c3 100644 --- a/src/utilities/outputParsers.spec.ts +++ b/src/utilities/outputParsers.spec.ts @@ -1,13 +1,20 @@ -import * as actionsCore from '@actions/core'; +import { jest } from '@jest/globals'; import { Result } from 'semantic-release'; -import { reportResults } from './outputParsers.js'; -const setOutputSpy = jest.spyOn(actionsCore, 'setOutput').mockImplementation(); +const setOutputSpy = jest.fn() as unknown as jest.SpiedFunction< + (_: never, packages: string[]) => unknown +>; + +jest.unstable_mockModule('@actions/core', (): unknown => ({ + setOutput: setOutputSpy, +})); describe('reportResults', (): void => { - it('sets output based on nextRelease', (): void => { + it('sets output based on nextRelease', async (): Promise => { expect.assertions(9); + const { reportResults } = await import('./outputParsers.js'); + const input: Result = { commits: [], lastRelease: { @@ -50,9 +57,11 @@ describe('reportResults', (): void => { expect(setOutputSpy).toHaveBeenCalledWith('git-tag', 'v1.1.1'); }); - it('sets prerelease and meta outputs if they are included in the version', (): void => { + it('sets prerelease and meta outputs if they are included in the version', async (): Promise => { expect.assertions(3); + const { reportResults } = await import('./outputParsers.js'); + const input: Result = { commits: [], lastRelease: { @@ -81,9 +90,11 @@ describe('reportResults', (): void => { expect(setOutputSpy).toHaveBeenCalledWith('build', 'build'); }); - it('throws an error if there is no released version', (): void => { + it('throws an error if there is no released version', async (): Promise => { expect.assertions(2); + const { reportResults } = await import('./outputParsers.js'); + reportResults(false); expect(setOutputSpy).toHaveBeenCalledTimes(1); diff --git a/src/utilities/parseConfiguration.spec.ts b/src/utilities/parseConfiguration.spec.ts index 8a9c3f55..e4097ff7 100644 --- a/src/utilities/parseConfiguration.spec.ts +++ b/src/utilities/parseConfiguration.spec.ts @@ -1,11 +1,19 @@ -import { promises as fs } from 'fs'; +import { jest } from '@jest/globals'; -import { parseConfiguration } from './parseConfiguration.js'; -const readFileSpy = jest.spyOn(fs, 'readFile'); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const readFileSpy = jest.fn() as jest.MockedFunction; + +jest.unstable_mockModule('fs', (): unknown => ({ + promises: { + readFile: readFileSpy, + }, +})); it('returns an object from a specified YAML file', async (): Promise => { expect.assertions(2); + const { parseConfiguration } = await import('./parseConfiguration.js'); + readFileSpy.mockResolvedValue('{foo: true}'); const config = await parseConfiguration('./dir/config.yml', {}); @@ -17,6 +25,8 @@ it('returns an object from a specified YAML file', async (): Promise => { it('throws if the YAML file is not parsed to an object', async (): Promise => { expect.assertions(1); + const { parseConfiguration } = await import('./parseConfiguration.js'); + readFileSpy.mockResolvedValue('foo'); try { @@ -29,8 +39,10 @@ it('throws if the YAML file is not parsed to an object', async (): Promise it('returns an object from a specified JS file', async (): Promise => { expect.assertions(1); + const { parseConfiguration } = await import('./parseConfiguration.js'); + readFileSpy.mockResolvedValue(` -module.exports = (defaultConfig) => ({ +export default (defaultConfig) => ({ ...defaultConfig, foo: 'bar', }); @@ -48,6 +60,8 @@ module.exports = (defaultConfig) => ({ it('throws if the JS module could not be imported', async (): Promise => { expect.assertions(1); + const { parseConfiguration } = await import('./parseConfiguration.js'); + readFileSpy.mockResolvedValue('foo'); try { diff --git a/src/utilities/parseConfiguration.ts b/src/utilities/parseConfiguration.ts index a775884c..f1a5d578 100644 --- a/src/utilities/parseConfiguration.ts +++ b/src/utilities/parseConfiguration.ts @@ -38,6 +38,8 @@ const parseJsConfiguration = async ( return config(defaultOptions); } catch (error: unknown) { + console.error(error); + throw new Error(`Could not import config file ${filePath}`); } };