Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/npm-development-e38a…
Browse files Browse the repository at this point in the history
…d2b2bb
  • Loading branch information
karpikpl authored Jul 3, 2024
2 parents 059382a + 593b13f commit beaf575
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 40 deletions.
38 changes: 22 additions & 16 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* Specifically, the inputs listed in `action.yml` should be set as environment
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

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')
Expand All @@ -24,7 +26,6 @@ let errorMock: jest.SpiedFunction<typeof core.error>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>
let githubApi: Octokit
let getReleaseMock: jest.SpyInstance
let updateReleaseMock: jest.SpyInstance
let getOctokitMock: jest.SpyInstance
Expand All @@ -33,24 +34,29 @@ let getWorkItemsBatchMock: jest.SpiedFunction<typeof azdo.getWorkItemsBatch>
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')
Expand Down
9 changes: 9 additions & 0 deletions __tests__/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"allowImportingTsExtensions": true
},
"include": ["src/**/*"]
}
133 changes: 113 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit beaf575

Please sign in to comment.