Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

14 changes: 9 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"es2022": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
"SharedArrayBuffer": "readonly",
"vi": "readonly",
"describe": "readonly",
"test": "readonly",
"expect": "readonly",
"beforeEach": "readonly",
"afterEach": "readonly"
},
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {}
Expand Down
19 changes: 8 additions & 11 deletions __tests__/functions/actions-status.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as core from '@actions/core'
import {actionStatus} from '../../src/functions/action-status'
import {truncateCommentBody} from '../../src/functions/truncate-comment-body'
import {API_HEADERS} from '../../src/functions/api-headers'
import {vi, expect, test, beforeEach} from 'vitest'
import {actionStatus} from '../../src/functions/action-status.js'
import {truncateCommentBody} from '../../src/functions/truncate-comment-body.js'
import {API_HEADERS} from '../../src/functions/api-headers.js'

var context
var octokit
beforeEach(() => {
jest.clearAllMocks()

jest.spyOn(core, 'debug').mockImplementation(() => {})
jest.spyOn(core, 'warning').mockImplementation(() => {})
vi.clearAllMocks()

process.env.GITHUB_SERVER_URL = 'https://github.com'
process.env.GITHUB_RUN_ID = '12345'
Expand All @@ -32,15 +29,15 @@ beforeEach(() => {
octokit = {
rest: {
reactions: {
createForIssueComment: jest.fn().mockReturnValueOnce({
createForIssueComment: vi.fn().mockReturnValueOnce({
data: {}
}),
deleteForIssueComment: jest.fn().mockReturnValueOnce({
deleteForIssueComment: vi.fn().mockReturnValueOnce({
data: {}
})
},
issues: {
createComment: jest.fn().mockReturnValueOnce({
createComment: vi.fn().mockReturnValueOnce({
data: {}
})
}
Expand Down
55 changes: 27 additions & 28 deletions __tests__/functions/admin.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {isAdmin} from '../../src/functions/admin'
import {COLORS} from '../../src/functions/colors'
import {isAdmin} from '../../src/functions/admin.js'
import {vi, expect, test, beforeEach} from 'vitest'
import {COLORS} from '../../src/functions/colors.js'
import * as github from '@actions/github'
import * as core from '@actions/core'

const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
// const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
const debugMock = vi.spyOn(core, 'debug')
const warningMock = vi.spyOn(core, 'warning')

class NotFoundError extends Error {
constructor(message) {
Expand All @@ -24,8 +24,7 @@ class WildError extends Error {
var context
var octokit
beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'info').mockImplementation(() => {})
vi.clearAllMocks()
process.env.INPUT_ADMINS_PAT = 'faketoken'
process.env.INPUT_ADMINS =
'MoNaLiSa,@lisamona,octoawesome/octo-awEsome-team,bad$user'
Expand All @@ -35,24 +34,24 @@ beforeEach(() => {
}

octokit = {
request: jest.fn().mockReturnValueOnce({
request: vi.fn().mockReturnValueOnce({
status: 204
}),
rest: {
orgs: {
get: jest.fn().mockReturnValueOnce({
get: vi.fn().mockReturnValueOnce({
data: {id: '12345'}
})
},
teams: {
getByName: jest.fn().mockReturnValueOnce({
getByName: vi.fn().mockReturnValueOnce({
data: {id: '567890'}
})
}
}
}

jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return octokit
})
})
Expand Down Expand Up @@ -117,11 +116,11 @@ test('runs isAdmin checks for an org team and finds a valid user', async () => {

// This only handles the global failure case of any 404 in the admin.js file
test('runs isAdmin checks for an org team and does not find the org', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
rest: {
orgs: {
get: jest
get: vi
.fn()
.mockRejectedValueOnce(
new NotFoundError('Reference does not exist')
Expand All @@ -139,16 +138,16 @@ test('runs isAdmin checks for an org team and does not find the org', async () =

// This only handles the global failure case of any 404 in the admin.js file
test('runs isAdmin checks for an org team and does not find the team', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
rest: {
orgs: {
get: jest.fn().mockReturnValueOnce({
get: vi.fn().mockReturnValueOnce({
data: {id: '12345'}
})
},
teams: {
getByName: jest
getByName: vi
.fn()
.mockRejectedValueOnce(
new NotFoundError('Reference does not exist')
Expand All @@ -166,19 +165,19 @@ test('runs isAdmin checks for an org team and does not find the team', async ()

// This test correctly tests if a user is a member of a team or not. If they are in a team a 204 is returned. If they are not a 404 is returned like in this test example
test('runs isAdmin checks for an org team and does not find the user in the team', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
request: jest
request: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('Reference does not exist')),
rest: {
orgs: {
get: jest.fn().mockReturnValueOnce({
get: vi.fn().mockReturnValueOnce({
data: {id: '12345'}
})
},
teams: {
getByName: jest.fn().mockReturnValueOnce({
getByName: vi.fn().mockReturnValueOnce({
data: {id: '567890'}
})
}
Expand All @@ -193,19 +192,19 @@ test('runs isAdmin checks for an org team and does not find the user in the team
})

test('runs isAdmin checks for an org team and an unexpected status code is received from the request method with octokit', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
request: jest.fn().mockReturnValueOnce({
request: vi.fn().mockReturnValueOnce({
status: 500
}),
rest: {
orgs: {
get: jest.fn().mockReturnValueOnce({
get: vi.fn().mockReturnValueOnce({
data: {id: '12345'}
})
},
teams: {
getByName: jest.fn().mockReturnValueOnce({
getByName: vi.fn().mockReturnValueOnce({
data: {id: '567890'}
})
}
Expand All @@ -221,19 +220,19 @@ test('runs isAdmin checks for an org team and an unexpected status code is recei
})

test('runs isAdmin checks for an org team and an unexpected error is thrown from any API call', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
request: jest
request: vi
.fn()
.mockRejectedValueOnce(new WildError('something went boom')),
rest: {
orgs: {
get: jest.fn().mockReturnValueOnce({
get: vi.fn().mockReturnValueOnce({
data: {id: '12345'}
})
},
teams: {
getByName: jest.fn().mockReturnValueOnce({
getByName: vi.fn().mockReturnValueOnce({
data: {id: '567890'}
})
}
Expand Down
40 changes: 19 additions & 21 deletions __tests__/functions/branch-ruleset-checks.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {branchRulesetChecks} from '../../src/functions/branch-ruleset-checks'
import {branchRulesetChecks} from '../../src/functions/branch-ruleset-checks.js'
import {vi, expect, test, beforeEach} from 'vitest'
import * as core from '@actions/core'
import {COLORS} from '../../src/functions/colors'
import {SUGGESTED_RULESETS} from '../../src/functions/suggested-rulesets'
import {ERROR} from '../../src/functions/templates/error'
import {COLORS} from '../../src/functions/colors.js'
import {SUGGESTED_RULESETS} from '../../src/functions/suggested-rulesets.js'
import {ERROR} from '../../src/functions/templates/error.js'

const debugMock = vi.spyOn(core, 'debug')
const infoMock = vi.spyOn(core, 'info')
const warningMock = vi.spyOn(core, 'warning')

var context
var octokit
var data
var rulesets

const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})

class ForbiddenError extends Error {
constructor(message) {
super(message)
Expand All @@ -21,10 +22,7 @@ class ForbiddenError extends Error {
}

beforeEach(() => {
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
jest.spyOn(core, 'warning').mockImplementation(() => {})
jest.clearAllMocks()
vi.clearAllMocks()

data = {
branch: 'main'
Expand Down Expand Up @@ -79,7 +77,7 @@ beforeEach(() => {
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand All @@ -89,7 +87,7 @@ test('finds that no branch protections or rulesets are defined', async () => {
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: []})
getBranchRules: vi.fn().mockReturnValueOnce({data: []})
}
}
}
Expand Down Expand Up @@ -119,7 +117,7 @@ test('finds that the branch ruleset is missing the deletion rule', async () => {
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand Down Expand Up @@ -150,7 +148,7 @@ test('finds that the branch ruleset is missing the dismiss_stale_reviews_on_push
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand All @@ -175,7 +173,7 @@ test('finds that all suggested branch rulesets are defined', async () => {
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand Down Expand Up @@ -214,7 +212,7 @@ test('finds that all suggested branch rulesets are defined but required reviews
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand Down Expand Up @@ -252,7 +250,7 @@ test('should still pass even with many required reviewers', async () => {
octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
}
}
}
Expand All @@ -271,7 +269,7 @@ test('fails due to a 403 from the GitHub API due to a repository being private o
octokit = {
rest: {
repos: {
getBranchRules: jest
getBranchRules: vi
.fn()
.mockRejectedValueOnce(
new ForbiddenError(ERROR.messages.upgrade_or_public.message)
Expand All @@ -293,7 +291,7 @@ test('fails due to an unknown 403 from the GitHub API', async () => {
octokit = {
rest: {
repos: {
getBranchRules: jest
getBranchRules: vi
.fn()
.mockRejectedValueOnce(new ForbiddenError(errorMessage))
}
Expand Down
3 changes: 2 additions & 1 deletion __tests__/functions/check-input.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {checkInput} from '../../src/functions/check-input'
import {checkInput} from '../../src/functions/check-input.js'
import {vi, expect, test, beforeEach} from 'vitest'

test('checks an input an finds that it is valid', async () => {
expect(checkInput('production')).toStrictEqual('production')
Expand Down
Loading