Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: resolve rebase conflicts and update tests for Vitest migration
- Fixed ESM import conflicts in src/main.js (added .js extensions)
- Updated all test files to use Vitest (vi) instead of Jest
- Added missing imports in test files
- Mocked actionStatus in environment-targets.test.js
- Regenerated dist files with correct source maps
- All tests passing with 100% coverage
  • Loading branch information
xakraz committed Nov 8, 2025
commit 129fa6950d12c9786d21328e12cb037bd53c201f
5 changes: 3 additions & 2 deletions __tests__/functions/deployment.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import {vi, expect, test, beforeEach} from 'vitest'
import {
createDeploymentStatus,
Expand Down Expand Up @@ -418,7 +419,7 @@ test('returns active deployment with matching task on first page', async () => {
})

test('returns active deployment with matching task during pagination', async () => {
octokit.graphql = jest
octokit.graphql = vi
.fn()
.mockReturnValueOnce({
repository: {
Expand Down Expand Up @@ -480,7 +481,7 @@ test('returns active deployment with matching task during pagination', async ()
})

test('returns null when no active deployment found after pagination with task filter', async () => {
octokit.graphql = jest
octokit.graphql = vi
.fn()
.mockReturnValueOnce({
repository: {
Expand Down
4 changes: 4 additions & 0 deletions __tests__/functions/environment-targets.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {environmentTargets} from '../../src/functions/environment-targets.js'
import {vi, expect, test, beforeEach} from 'vitest'
import * as core from '@actions/core'
import * as actionStatus from '../../src/functions/action-status.js'
import dedent from 'dedent-js'
import {COLORS} from '../../src/functions/colors.js'

Expand All @@ -12,6 +13,9 @@ const warningMock = vi.spyOn(core, 'warning')

beforeEach(() => {
vi.clearAllMocks()
vi.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
return true
})

process.env.INPUT_ENVIRONMENT_TARGETS = 'production,development,staging'
process.env.INPUT_GLOBAL_LOCK_FLAG = '--global'
Expand Down
104 changes: 51 additions & 53 deletions __tests__/functions/lock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ test('throws an error if an unhandled exception occurs', async () => {
})

test('successfully obtains a deployment lock (sticky) with a task and creates a lock comment with task information', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand All @@ -1086,21 +1086,21 @@ test('successfully obtains a deployment lock (sticky) with a task and creates a
const octokitWithTask = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('Reference does not exist'))
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
createOrUpdateFileContents: jest.fn().mockReturnValue({}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
createOrUpdateFileContents: vi.fn().mockReturnValue({}),
getContent: vi
.fn()
.mockRejectedValue(new NotFoundError('file not found'))
},
git: {
createRef: jest.fn().mockReturnValue({status: 201})
createRef: vi.fn().mockReturnValue({status: 201})
},
issues: {
createComment: jest.fn().mockReturnValue({})
createComment: vi.fn().mockReturnValue({})
}
}
}
Expand Down Expand Up @@ -1155,8 +1155,8 @@ test('successfully obtains a deployment lock (sticky) with a task and creates a

// Tests for enhanced ownership checks with branch comparison (lines 424-573)
test('Enhanced ownership check: same user, same branch - owner already has lock (sticky=true, leaveComment=true) with task', async () => {
const warningMock = jest.spyOn(core, 'warning')
const actionStatusSpy = jest
const warningMock = vi.spyOn(core, 'warning')
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1190,11 +1190,11 @@ test('Enhanced ownership check: same user, same branch - owner already has lock
const octokitOwnerLock = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
Expand Down Expand Up @@ -1267,7 +1267,7 @@ test('Enhanced ownership check: same user, same branch - owner already has lock
})

test('Enhanced ownership check: same user, same branch - global lock with task (sticky=true, leaveComment=true)', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1301,11 +1301,11 @@ test('Enhanced ownership check: same user, same branch - global lock with task (
const octokitOwnerLock = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockReturnValueOnce({
data: {content: lockBase64OctocatGlobalWithTask}
Expand Down Expand Up @@ -1380,8 +1380,8 @@ test('Enhanced ownership check: same user, same branch - global lock with task (
})

test('Enhanced ownership check: same user, different branch - denies lock access', async () => {
const warningMock = jest.spyOn(core, 'warning')
const actionStatusSpy = jest
const warningMock = vi.spyOn(core, 'warning')
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1417,11 +1417,11 @@ test('Enhanced ownership check: same user, different branch - denies lock access
const octokitDifferentBranch = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({
Expand Down Expand Up @@ -1488,7 +1488,7 @@ test('Enhanced ownership check: same user, different branch - denies lock access
})

test('Enhanced ownership check: different user trying to claim lock - shows detailed error with task', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1524,11 +1524,11 @@ test('Enhanced ownership check: different user trying to claim lock - shows deta
const octokitDifferentUser = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
Expand Down Expand Up @@ -1604,7 +1604,7 @@ test('Enhanced ownership check: different user trying to claim lock - shows deta
})

test('Enhanced ownership check: different user trying to claim lock WITHOUT task - shows detailed error', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1640,11 +1640,11 @@ test('Enhanced ownership check: different user trying to claim lock WITHOUT task
const octokitDifferentUser = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64MonalisaNoTask}})
Expand Down Expand Up @@ -1720,7 +1720,7 @@ test('Enhanced ownership check: different user trying to claim lock WITHOUT task
})

test('Enhanced ownership check: different user trying to claim global lock - shows detailed error', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1756,15 +1756,13 @@ test('Enhanced ownership check: different user trying to claim global lock - sho
const octokitGlobalLock = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
.fn()
.mockReturnValueOnce({
data: {content: lockBase64OctocatGlobalWithTask}
})
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi.fn().mockReturnValueOnce({
data: {content: lockBase64OctocatGlobalWithTask}
})
}
}
}
Expand Down Expand Up @@ -1809,7 +1807,7 @@ test('Enhanced ownership check: different user trying to claim global lock - sho
})

test('Enhanced ownership check: same user, same branch - sticky=false, leaveComment=false (with task)', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1843,11 +1841,11 @@ test('Enhanced ownership check: same user, same branch - sticky=false, leaveComm
const octokitOwnerLock = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
Expand Down Expand Up @@ -1902,7 +1900,7 @@ test('Enhanced ownership check: same user, same branch - sticky=false, leaveComm
})

test('Enhanced ownership check: different user with reason in lock - shows reason in error', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -1938,11 +1936,11 @@ test('Enhanced ownership check: different user with reason in lock - shows reaso
const octokitWithReason = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({
Expand Down Expand Up @@ -1992,7 +1990,7 @@ test('Enhanced ownership check: different user with reason in lock - shows reaso
})

test('Enhanced ownership check: different user with lock WITHOUT task - shows detailed error (covers line 528 else branch)', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -2028,11 +2026,11 @@ test('Enhanced ownership check: different user with lock WITHOUT task - shows de
const octokitNoTask = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64OctocatNoTask}})
Expand Down Expand Up @@ -2079,7 +2077,7 @@ test('Enhanced ownership check: different user with lock WITHOUT task - shows de
})

test('Enhanced ownership check: different user with lock WITH task but WITHOUT pr_number - covers all branch combinations', async () => {
const actionStatusSpy = jest
const actionStatusSpy = vi
.spyOn(actionStatus, 'actionStatus')
.mockImplementation(() => {
return undefined
Expand Down Expand Up @@ -2115,11 +2113,11 @@ test('Enhanced ownership check: different user with lock WITH task but WITHOUT p
const octokitWithTaskNoPR = {
rest: {
repos: {
getBranch: jest
getBranch: vi
.fn()
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: jest
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
getContent: vi
.fn()
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
.mockReturnValueOnce({data: {content: lockBase64WithTaskNoPR}})
Expand Down
Loading