Skip to content

Commit 129fa69

Browse files
committed
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
1 parent 8a26878 commit 129fa69

File tree

9 files changed

+247
-191
lines changed

9 files changed

+247
-191
lines changed

__tests__/functions/deployment.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as core from '@actions/core'
12
import {vi, expect, test, beforeEach} from 'vitest'
23
import {
34
createDeploymentStatus,
@@ -418,7 +419,7 @@ test('returns active deployment with matching task on first page', async () => {
418419
})
419420

420421
test('returns active deployment with matching task during pagination', async () => {
421-
octokit.graphql = jest
422+
octokit.graphql = vi
422423
.fn()
423424
.mockReturnValueOnce({
424425
repository: {
@@ -480,7 +481,7 @@ test('returns active deployment with matching task during pagination', async ()
480481
})
481482

482483
test('returns null when no active deployment found after pagination with task filter', async () => {
483-
octokit.graphql = jest
484+
octokit.graphql = vi
484485
.fn()
485486
.mockReturnValueOnce({
486487
repository: {

__tests__/functions/environment-targets.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {environmentTargets} from '../../src/functions/environment-targets.js'
22
import {vi, expect, test, beforeEach} from 'vitest'
33
import * as core from '@actions/core'
4+
import * as actionStatus from '../../src/functions/action-status.js'
45
import dedent from 'dedent-js'
56
import {COLORS} from '../../src/functions/colors.js'
67

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

1314
beforeEach(() => {
1415
vi.clearAllMocks()
16+
vi.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
17+
return true
18+
})
1519

1620
process.env.INPUT_ENVIRONMENT_TARGETS = 'production,development,staging'
1721
process.env.INPUT_GLOBAL_LOCK_FLAG = '--global'

__tests__/functions/lock.test.js

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ test('throws an error if an unhandled exception occurs', async () => {
10701070
})
10711071

10721072
test('successfully obtains a deployment lock (sticky) with a task and creates a lock comment with task information', async () => {
1073-
const actionStatusSpy = jest
1073+
const actionStatusSpy = vi
10741074
.spyOn(actionStatus, 'actionStatus')
10751075
.mockImplementation(() => {
10761076
return undefined
@@ -1086,21 +1086,21 @@ test('successfully obtains a deployment lock (sticky) with a task and creates a
10861086
const octokitWithTask = {
10871087
rest: {
10881088
repos: {
1089-
getBranch: jest
1089+
getBranch: vi
10901090
.fn()
10911091
.mockRejectedValueOnce(new NotFoundError('Reference does not exist'))
10921092
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1093-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1094-
createOrUpdateFileContents: jest.fn().mockReturnValue({}),
1095-
getContent: jest
1093+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1094+
createOrUpdateFileContents: vi.fn().mockReturnValue({}),
1095+
getContent: vi
10961096
.fn()
10971097
.mockRejectedValue(new NotFoundError('file not found'))
10981098
},
10991099
git: {
1100-
createRef: jest.fn().mockReturnValue({status: 201})
1100+
createRef: vi.fn().mockReturnValue({status: 201})
11011101
},
11021102
issues: {
1103-
createComment: jest.fn().mockReturnValue({})
1103+
createComment: vi.fn().mockReturnValue({})
11041104
}
11051105
}
11061106
}
@@ -1155,8 +1155,8 @@ test('successfully obtains a deployment lock (sticky) with a task and creates a
11551155

11561156
// Tests for enhanced ownership checks with branch comparison (lines 424-573)
11571157
test('Enhanced ownership check: same user, same branch - owner already has lock (sticky=true, leaveComment=true) with task', async () => {
1158-
const warningMock = jest.spyOn(core, 'warning')
1159-
const actionStatusSpy = jest
1158+
const warningMock = vi.spyOn(core, 'warning')
1159+
const actionStatusSpy = vi
11601160
.spyOn(actionStatus, 'actionStatus')
11611161
.mockImplementation(() => {
11621162
return undefined
@@ -1190,11 +1190,11 @@ test('Enhanced ownership check: same user, same branch - owner already has lock
11901190
const octokitOwnerLock = {
11911191
rest: {
11921192
repos: {
1193-
getBranch: jest
1193+
getBranch: vi
11941194
.fn()
11951195
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1196-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1197-
getContent: jest
1196+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1197+
getContent: vi
11981198
.fn()
11991199
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
12001200
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
@@ -1267,7 +1267,7 @@ test('Enhanced ownership check: same user, same branch - owner already has lock
12671267
})
12681268

12691269
test('Enhanced ownership check: same user, same branch - global lock with task (sticky=true, leaveComment=true)', async () => {
1270-
const actionStatusSpy = jest
1270+
const actionStatusSpy = vi
12711271
.spyOn(actionStatus, 'actionStatus')
12721272
.mockImplementation(() => {
12731273
return undefined
@@ -1301,11 +1301,11 @@ test('Enhanced ownership check: same user, same branch - global lock with task (
13011301
const octokitOwnerLock = {
13021302
rest: {
13031303
repos: {
1304-
getBranch: jest
1304+
getBranch: vi
13051305
.fn()
13061306
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1307-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1308-
getContent: jest
1307+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1308+
getContent: vi
13091309
.fn()
13101310
.mockReturnValueOnce({
13111311
data: {content: lockBase64OctocatGlobalWithTask}
@@ -1380,8 +1380,8 @@ test('Enhanced ownership check: same user, same branch - global lock with task (
13801380
})
13811381

13821382
test('Enhanced ownership check: same user, different branch - denies lock access', async () => {
1383-
const warningMock = jest.spyOn(core, 'warning')
1384-
const actionStatusSpy = jest
1383+
const warningMock = vi.spyOn(core, 'warning')
1384+
const actionStatusSpy = vi
13851385
.spyOn(actionStatus, 'actionStatus')
13861386
.mockImplementation(() => {
13871387
return undefined
@@ -1417,11 +1417,11 @@ test('Enhanced ownership check: same user, different branch - denies lock access
14171417
const octokitDifferentBranch = {
14181418
rest: {
14191419
repos: {
1420-
getBranch: jest
1420+
getBranch: vi
14211421
.fn()
14221422
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1423-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1424-
getContent: jest
1423+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1424+
getContent: vi
14251425
.fn()
14261426
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
14271427
.mockReturnValueOnce({
@@ -1488,7 +1488,7 @@ test('Enhanced ownership check: same user, different branch - denies lock access
14881488
})
14891489

14901490
test('Enhanced ownership check: different user trying to claim lock - shows detailed error with task', async () => {
1491-
const actionStatusSpy = jest
1491+
const actionStatusSpy = vi
14921492
.spyOn(actionStatus, 'actionStatus')
14931493
.mockImplementation(() => {
14941494
return undefined
@@ -1524,11 +1524,11 @@ test('Enhanced ownership check: different user trying to claim lock - shows deta
15241524
const octokitDifferentUser = {
15251525
rest: {
15261526
repos: {
1527-
getBranch: jest
1527+
getBranch: vi
15281528
.fn()
15291529
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1530-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1531-
getContent: jest
1530+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1531+
getContent: vi
15321532
.fn()
15331533
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
15341534
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
@@ -1604,7 +1604,7 @@ test('Enhanced ownership check: different user trying to claim lock - shows deta
16041604
})
16051605

16061606
test('Enhanced ownership check: different user trying to claim lock WITHOUT task - shows detailed error', async () => {
1607-
const actionStatusSpy = jest
1607+
const actionStatusSpy = vi
16081608
.spyOn(actionStatus, 'actionStatus')
16091609
.mockImplementation(() => {
16101610
return undefined
@@ -1640,11 +1640,11 @@ test('Enhanced ownership check: different user trying to claim lock WITHOUT task
16401640
const octokitDifferentUser = {
16411641
rest: {
16421642
repos: {
1643-
getBranch: jest
1643+
getBranch: vi
16441644
.fn()
16451645
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1646-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1647-
getContent: jest
1646+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1647+
getContent: vi
16481648
.fn()
16491649
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
16501650
.mockReturnValueOnce({data: {content: lockBase64MonalisaNoTask}})
@@ -1720,7 +1720,7 @@ test('Enhanced ownership check: different user trying to claim lock WITHOUT task
17201720
})
17211721

17221722
test('Enhanced ownership check: different user trying to claim global lock - shows detailed error', async () => {
1723-
const actionStatusSpy = jest
1723+
const actionStatusSpy = vi
17241724
.spyOn(actionStatus, 'actionStatus')
17251725
.mockImplementation(() => {
17261726
return undefined
@@ -1756,15 +1756,13 @@ test('Enhanced ownership check: different user trying to claim global lock - sho
17561756
const octokitGlobalLock = {
17571757
rest: {
17581758
repos: {
1759-
getBranch: jest
1759+
getBranch: vi
17601760
.fn()
17611761
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1762-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1763-
getContent: jest
1764-
.fn()
1765-
.mockReturnValueOnce({
1766-
data: {content: lockBase64OctocatGlobalWithTask}
1767-
})
1762+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1763+
getContent: vi.fn().mockReturnValueOnce({
1764+
data: {content: lockBase64OctocatGlobalWithTask}
1765+
})
17681766
}
17691767
}
17701768
}
@@ -1809,7 +1807,7 @@ test('Enhanced ownership check: different user trying to claim global lock - sho
18091807
})
18101808

18111809
test('Enhanced ownership check: same user, same branch - sticky=false, leaveComment=false (with task)', async () => {
1812-
const actionStatusSpy = jest
1810+
const actionStatusSpy = vi
18131811
.spyOn(actionStatus, 'actionStatus')
18141812
.mockImplementation(() => {
18151813
return undefined
@@ -1843,11 +1841,11 @@ test('Enhanced ownership check: same user, same branch - sticky=false, leaveComm
18431841
const octokitOwnerLock = {
18441842
rest: {
18451843
repos: {
1846-
getBranch: jest
1844+
getBranch: vi
18471845
.fn()
18481846
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1849-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1850-
getContent: jest
1847+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1848+
getContent: vi
18511849
.fn()
18521850
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
18531851
.mockReturnValueOnce({data: {content: lockBase64MonalisaWithTask}})
@@ -1902,7 +1900,7 @@ test('Enhanced ownership check: same user, same branch - sticky=false, leaveComm
19021900
})
19031901

19041902
test('Enhanced ownership check: different user with reason in lock - shows reason in error', async () => {
1905-
const actionStatusSpy = jest
1903+
const actionStatusSpy = vi
19061904
.spyOn(actionStatus, 'actionStatus')
19071905
.mockImplementation(() => {
19081906
return undefined
@@ -1938,11 +1936,11 @@ test('Enhanced ownership check: different user with reason in lock - shows reaso
19381936
const octokitWithReason = {
19391937
rest: {
19401938
repos: {
1941-
getBranch: jest
1939+
getBranch: vi
19421940
.fn()
19431941
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
1944-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
1945-
getContent: jest
1942+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
1943+
getContent: vi
19461944
.fn()
19471945
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
19481946
.mockReturnValueOnce({
@@ -1992,7 +1990,7 @@ test('Enhanced ownership check: different user with reason in lock - shows reaso
19921990
})
19931991

19941992
test('Enhanced ownership check: different user with lock WITHOUT task - shows detailed error (covers line 528 else branch)', async () => {
1995-
const actionStatusSpy = jest
1993+
const actionStatusSpy = vi
19961994
.spyOn(actionStatus, 'actionStatus')
19971995
.mockImplementation(() => {
19981996
return undefined
@@ -2028,11 +2026,11 @@ test('Enhanced ownership check: different user with lock WITHOUT task - shows de
20282026
const octokitNoTask = {
20292027
rest: {
20302028
repos: {
2031-
getBranch: jest
2029+
getBranch: vi
20322030
.fn()
20332031
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
2034-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
2035-
getContent: jest
2032+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
2033+
getContent: vi
20362034
.fn()
20372035
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
20382036
.mockReturnValueOnce({data: {content: lockBase64OctocatNoTask}})
@@ -2079,7 +2077,7 @@ test('Enhanced ownership check: different user with lock WITHOUT task - shows de
20792077
})
20802078

20812079
test('Enhanced ownership check: different user with lock WITH task but WITHOUT pr_number - covers all branch combinations', async () => {
2082-
const actionStatusSpy = jest
2080+
const actionStatusSpy = vi
20832081
.spyOn(actionStatus, 'actionStatus')
20842082
.mockImplementation(() => {
20852083
return undefined
@@ -2115,11 +2113,11 @@ test('Enhanced ownership check: different user with lock WITH task but WITHOUT p
21152113
const octokitWithTaskNoPR = {
21162114
rest: {
21172115
repos: {
2118-
getBranch: jest
2116+
getBranch: vi
21192117
.fn()
21202118
.mockReturnValueOnce({data: {commit: {sha: 'abc123'}}}),
2121-
get: jest.fn().mockReturnValue({data: {default_branch: 'main'}}),
2122-
getContent: jest
2119+
get: vi.fn().mockReturnValue({data: {default_branch: 'main'}}),
2120+
getContent: vi
21232121
.fn()
21242122
.mockRejectedValueOnce(new NotFoundError('file not found')) // global lock check
21252123
.mockReturnValueOnce({data: {content: lockBase64WithTaskNoPR}})

0 commit comments

Comments
 (0)