diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 524573c..ba2d9ab 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -5,16 +5,18 @@ * Specifically, the inputs listed in `action.yml` should be set as environment * variables following the pattern `INPUT_`. */ - import * as core from '@actions/core' -import * as github from '@actions/github' import * as main from '../src/main' -import { Octokit } from '@octokit/rest' import { mockInputs } from './mock.helper' import * as azdo from '../src/azdo' import { WorkItemsBatchResponse } from '../src/azdoTypes' import fs from 'fs' import path from 'path' +import * as github from '@actions/github' + +jest.mock('@actions/github', () => ({ + getOctokit: jest.fn() +})) // Mock the action's main function const runMock = jest.spyOn(main, 'run') @@ -24,7 +26,6 @@ let errorMock: jest.SpiedFunction let getInputMock: jest.SpiedFunction let setFailedMock: jest.SpiedFunction let setOutputMock: jest.SpiedFunction -let githubApi: Octokit let getReleaseMock: jest.SpyInstance let updateReleaseMock: jest.SpyInstance let getOctokitMock: jest.SpyInstance @@ -33,24 +34,29 @@ let getWorkItemsBatchMock: jest.SpiedFunction describe('action', () => { beforeEach(() => { jest.clearAllMocks() - githubApi = new Octokit() + // githubApi = new GitHub() errorMock = jest.spyOn(core, 'error').mockImplementation() getInputMock = jest.spyOn(core, 'getInput').mockImplementation() setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() + getReleaseMock = jest.fn() + updateReleaseMock = jest.fn() - getReleaseMock = jest - .spyOn(githubApi.rest.repos, 'getRelease') - .mockImplementation() - updateReleaseMock = jest - .spyOn(githubApi.rest.repos, 'updateRelease') - .mockImplementation() - getOctokitMock = jest - .spyOn(github, 'getOctokit') - .mockImplementation() - /* eslint-disable @typescript-eslint/no-explicit-any */ - .mockReturnValue(githubApi as any) + const mockOctokitInstance = { + rest: { + repos: { + getRelease: getReleaseMock, + updateRelease: updateReleaseMock + } + } + // Add other mocked methods as needed + } + + getOctokitMock = github.getOctokit as jest.MockedFunction< + typeof github.getOctokit + > + getOctokitMock.mockReturnValue(mockOctokitInstance) getWorkItemsBatchMock = jest .spyOn(azdo, 'getWorkItemsBatch') diff --git a/__tests__/tsconfig.test.json b/__tests__/tsconfig.test.json new file mode 100644 index 0000000..cf1f200 --- /dev/null +++ b/__tests__/tsconfig.test.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": false, + "noEmit": true, + "allowImportingTsExtensions": true + }, + "include": ["src/**/*"] +} diff --git a/package-lock.json b/package-lock.json index 9d7a199..8f3d769 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@jest/globals": "^29.7.0", - "@octokit/rest": "^20.1.1", + "@octokit/rest": "^21.0.0", "@types/jest": "^29.5.12", "@types/node": "^20.14.9", "@typescript-eslint/eslint-plugin": "^7.15.0", @@ -1447,18 +1447,6 @@ "@octokit/openapi-types": "^20.0.0" } }, - "node_modules/@octokit/plugin-request-log": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-4.0.1.tgz", - "integrity": "sha512-GihNqNpGHorUrO7Qa9JbAl0dbLnqJVrV8OXe2Zm5/Y4wFkZQDfTreBzVmiRfJVfE4mClXdihHnbpyyO9FSX4HA==", - "dev": true, - "engines": { - "node": ">= 18" - }, - "peerDependencies": { - "@octokit/core": "5" - } - }, "node_modules/@octokit/plugin-rest-endpoint-methods": { "version": "10.4.1", "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.4.1.tgz", @@ -1514,15 +1502,69 @@ } }, "node_modules/@octokit/rest": { - "version": "20.1.1", - "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-20.1.1.tgz", - "integrity": "sha512-MB4AYDsM5jhIHro/dq4ix1iWTLGToIGk6cWF5L6vanFaMble5jTX/UBQyiv05HsWnwUtY8JrfHy2LWfKwihqMw==", + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-21.0.0.tgz", + "integrity": "sha512-XudXXOmiIjivdjNZ+fN71NLrnDM00sxSZlhqmPR3v0dVoJwyP628tSlc12xqn8nX3N0965583RBw5GPo6r8u4Q==", "dev": true, "dependencies": { - "@octokit/core": "^5.0.2", - "@octokit/plugin-paginate-rest": "11.3.1", - "@octokit/plugin-request-log": "^4.0.0", - "@octokit/plugin-rest-endpoint-methods": "13.2.2" + "@octokit/core": "^6.1.2", + "@octokit/plugin-paginate-rest": "^11.0.0", + "@octokit/plugin-request-log": "^5.1.0", + "@octokit/plugin-rest-endpoint-methods": "^13.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/auth-token": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.1.tgz", + "integrity": "sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==", + "dev": true, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/core": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.2.tgz", + "integrity": "sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==", + "dev": true, + "dependencies": { + "@octokit/auth-token": "^5.0.0", + "@octokit/graphql": "^8.0.0", + "@octokit/request": "^9.0.0", + "@octokit/request-error": "^6.0.1", + "@octokit/types": "^13.0.0", + "before-after-hook": "^3.0.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/endpoint": { + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.1.tgz", + "integrity": "sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q==", + "dev": true, + "dependencies": { + "@octokit/types": "^13.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/graphql": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.1.1.tgz", + "integrity": "sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg==", + "dev": true, + "dependencies": { + "@octokit/request": "^9.0.0", + "@octokit/types": "^13.0.0", + "universal-user-agent": "^7.0.0" }, "engines": { "node": ">= 18" @@ -1543,6 +1585,18 @@ "@octokit/core": "5" } }, + "node_modules/@octokit/rest/node_modules/@octokit/plugin-request-log": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-5.3.0.tgz", + "integrity": "sha512-FiGcyjdtYPlr03ExBk/0ysIlEFIFGJQAVoPPMxL19B24bVSEiZQnVGBunNtaAF1YnvE/EFoDpXmITtRnyCiypQ==", + "dev": true, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, "node_modules/@octokit/rest/node_modules/@octokit/plugin-rest-endpoint-methods": { "version": "13.2.2", "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.2.2.tgz", @@ -1558,6 +1612,45 @@ "@octokit/core": "^5" } }, + "node_modules/@octokit/rest/node_modules/@octokit/request": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.1.1.tgz", + "integrity": "sha512-pyAguc0p+f+GbQho0uNetNQMmLG1e80WjkIaqqgUkihqUp0boRU6nKItXO4VWnr+nbZiLGEyy4TeKRwqaLvYgw==", + "dev": true, + "dependencies": { + "@octokit/endpoint": "^10.0.0", + "@octokit/request-error": "^6.0.1", + "@octokit/types": "^13.1.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/request-error": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.1.tgz", + "integrity": "sha512-1mw1gqT3fR/WFvnoVpY/zUM2o/XkMs/2AszUUG9I69xn0JFLv6PGkPhNk5lbfvROs79wiS0bqiJNxfCZcRJJdg==", + "dev": true, + "dependencies": { + "@octokit/types": "^13.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/before-after-hook": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz", + "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", + "dev": true + }, + "node_modules/@octokit/rest/node_modules/universal-user-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", + "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", + "dev": true + }, "node_modules/@octokit/types": { "version": "13.5.0", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.5.0.tgz", diff --git a/package.json b/package.json index c5d2e99..92afdb9 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,14 @@ "lint": "npx eslint . -c ./.github/linters/.eslintrc.yml", "package": "npx ncc build src/index.ts -o dist --source-map --license licenses.txt", "package:watch": "npm run package -- --watch", - "test": "npx jest", + "test": "NODE_OPTIONS=--experimental-vm-modules npx jest", "all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package" }, "license": "MIT", "jest": { + "testEnvironmentOptions": { + "NODE_OPTIONS": "--experimental-vm-modules" + }, "preset": "ts-jest", "verbose": true, "clearMocks": true, @@ -92,7 +95,7 @@ }, "devDependencies": { "@jest/globals": "^29.7.0", - "@octokit/rest": "^20.1.1", + "@octokit/rest": "^21.0.0", "@types/jest": "^29.5.12", "@types/node": "^20.14.9", "@typescript-eslint/eslint-plugin": "^7.15.0", diff --git a/tsconfig.json b/tsconfig.json index 2f26aac..80d6b39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,9 @@ "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "target": "ES2022", - "module": "NodeNext", + "module": "node16", "rootDir": "./src", - "moduleResolution": "NodeNext", + "moduleResolution": "node16", "baseUrl": "./", "sourceMap": true, "outDir": "./dist",