Skip to content

Commit 7eac648

Browse files
Upgrade jest to v29 (#113)
* chore(deps): update unit test packages to v29 * test: use transform instead of globals for ts-jest setup * chore: format codes * chore: bump up for @types/jest * chore: bump up for jest and jest-circus --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent e227cc7 commit 7eac648

File tree

5 files changed

+2663
-6519
lines changed

5 files changed

+2663
-6519
lines changed

__tests__/handler.test.ts

+68-58
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('handlePullRequest', () => {
6767
test('exits the process if pull requests include skip words in the title', async () => {
6868
const spy = jest.spyOn(core, 'info')
6969

70-
context.payload.pull_request.title = 'wip test'
70+
context.payload.pull_request!.title = 'wip test'
7171

7272
const client = github.getOctokit('token')
7373
const config = {
@@ -104,7 +104,7 @@ describe('handlePullRequest', () => {
104104

105105
const spy = jest.spyOn(core, 'info')
106106

107-
context.payload.pull_request.draft = true
107+
context.payload.pull_request!.draft = true
108108

109109
const client = github.getOctokit('token')
110110
const config = {
@@ -158,8 +158,8 @@ describe('handlePullRequest', () => {
158158
await handler.handlePullRequest(client, context, config)
159159

160160
expect(addAssigneesSpy).not.toBeCalled()
161-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(3)
162-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
161+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(3)
162+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
163163
/reviewer/
164164
)
165165
})
@@ -194,8 +194,10 @@ describe('handlePullRequest', () => {
194194
await handler.handlePullRequest(client, context, config)
195195

196196
// THEN
197-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(1)
198-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch('pr-creator')
197+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(1)
198+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(
199+
'pr-creator'
200+
)
199201
expect(requestReviewersSpy).not.toBeCalled()
200202
})
201203

@@ -259,9 +261,9 @@ describe('handlePullRequest', () => {
259261

260262
await handler.handlePullRequest(client, context, config)
261263

262-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(3)
263-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/reviewer/)
264-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toEqual(
264+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(3)
265+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/reviewer/)
266+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toEqual(
265267
expect.arrayContaining(['reviewer1', 'reviewer2', 'reviewer3'])
266268
)
267269
expect(requestReviewersSpy).not.toBeCalled()
@@ -300,8 +302,8 @@ describe('handlePullRequest', () => {
300302

301303
await handler.handlePullRequest(client, context, config)
302304

303-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(1)
304-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toEqual(
305+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(1)
306+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toEqual(
305307
expect.arrayContaining(['assignee1'])
306308
)
307309
expect(requestReviewersSpy).not.toBeCalled()
@@ -339,10 +341,10 @@ describe('handlePullRequest', () => {
339341

340342
await handler.handlePullRequest(client, context, config)
341343

342-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(2)
343-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/assignee/)
344-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(2)
345-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
344+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(2)
345+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/assignee/)
346+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(2)
347+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
346348
/reviewer/
347349
)
348350
})
@@ -414,8 +416,8 @@ describe('handlePullRequest', () => {
414416

415417
await handler.handlePullRequest(client, context, config)
416418

417-
expect(spy.mock.calls[0][0].assignees).toHaveLength(2)
418-
expect(spy.mock.calls[0][0].assignees[0]).toMatch(/maintainer/)
419+
expect(spy.mock.calls[0][0]?.assignees).toHaveLength(2)
420+
expect(spy.mock.calls[0][0]?.assignees![0]).toMatch(/maintainer/)
419421
})
420422

421423
test('adds reviewers to pull requests if throws error to add assignees', async () => {
@@ -448,8 +450,8 @@ describe('handlePullRequest', () => {
448450

449451
await handler.handlePullRequest(client, context, config)
450452

451-
expect(spy.mock.calls[0][0].reviewers).toHaveLength(2)
452-
expect(spy.mock.calls[0][0].reviewers[0]).toMatch(/reviewer/)
453+
expect(spy.mock.calls[0][0]?.reviewers).toHaveLength(2)
454+
expect(spy.mock.calls[0][0]?.reviewers![0]).toMatch(/reviewer/)
453455
})
454456

455457
/*
@@ -542,8 +544,8 @@ describe('handlePullRequest', () => {
542544
await handler.handlePullRequest(client, context, config)
543545

544546
// THEN
545-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(1)
546-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
547+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(1)
548+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
547549
/reviewer/
548550
)
549551
expect(addAssigneesSpy).not.toBeCalled()
@@ -587,9 +589,13 @@ describe('handlePullRequest', () => {
587589
await handler.handlePullRequest(client, context, config)
588590

589591
// THEN
590-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(2)
591-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(/group1/)
592-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[1]).toMatch(/group2/)
592+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(2)
593+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
594+
/group1/
595+
)
596+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![1]).toMatch(
597+
/group2/
598+
)
593599
expect(addAssigneesSpy).not.toBeCalled()
594600
})
595601

@@ -631,10 +637,14 @@ describe('handlePullRequest', () => {
631637
await handler.handlePullRequest(client, context, config)
632638

633639
// THEN
634-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(3)
635-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(/group1/)
636-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[1]).toMatch(/group1/)
637-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[2]).toMatch(
640+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(3)
641+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
642+
/group1/
643+
)
644+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![1]).toMatch(
645+
/group1/
646+
)
647+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![2]).toMatch(
638648
/group2-user1/
639649
)
640650
expect(addAssigneesSpy).not.toBeCalled()
@@ -681,10 +691,10 @@ describe('handlePullRequest', () => {
681691
await handler.handlePullRequest(client, context, config)
682692

683693
// THEN
684-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(3)
685-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/group1/)
686-
expect(addAssigneesSpy.mock.calls[0][0].assignees[1]).toMatch(/group2/)
687-
expect(addAssigneesSpy.mock.calls[0][0].assignees[2]).toMatch(/group3/)
694+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(3)
695+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/group1/)
696+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![1]).toMatch(/group2/)
697+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![2]).toMatch(/group3/)
688698
expect(requestReviewersSpy).not.toBeCalled()
689699
})
690700

@@ -728,10 +738,10 @@ describe('handlePullRequest', () => {
728738
await handler.handlePullRequest(client, context, config)
729739

730740
// THEN
731-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(3)
732-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/group1/)
733-
expect(addAssigneesSpy.mock.calls[0][0].assignees[1]).toMatch(/group2/)
734-
expect(addAssigneesSpy.mock.calls[0][0].assignees[2]).toMatch(/group3/)
741+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(3)
742+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/group1/)
743+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![1]).toMatch(/group2/)
744+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![2]).toMatch(/group3/)
735745
expect(requestReviewersSpy).not.toBeCalled()
736746
})
737747

@@ -775,10 +785,10 @@ describe('handlePullRequest', () => {
775785
await handler.handlePullRequest(client, context, config)
776786

777787
// THEN
778-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(3)
779-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/group1/)
780-
expect(addAssigneesSpy.mock.calls[0][0].assignees[1]).toMatch(/group2/)
781-
expect(addAssigneesSpy.mock.calls[0][0].assignees[2]).toMatch(/group3/)
788+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(3)
789+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/group1/)
790+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![1]).toMatch(/group2/)
791+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![2]).toMatch(/group3/)
782792
expect(requestReviewersSpy).not.toBeCalled()
783793
})
784794

@@ -823,16 +833,16 @@ describe('handlePullRequest', () => {
823833
await handler.handlePullRequest(client, context, config)
824834

825835
// THEN
826-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(3)
827-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/group1/)
828-
expect(addAssigneesSpy.mock.calls[0][0].assignees[1]).toMatch(/group2/)
829-
expect(addAssigneesSpy.mock.calls[0][0].assignees[2]).toMatch(/group3/)
836+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(3)
837+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/group1/)
838+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![1]).toMatch(/group2/)
839+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![2]).toMatch(/group3/)
830840

831-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(2)
832-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
841+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(2)
842+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
833843
/reviewer/
834844
)
835-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[1]).toMatch(
845+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![1]).toMatch(
836846
/reviewer/
837847
)
838848
})
@@ -878,17 +888,17 @@ describe('handlePullRequest', () => {
878888
await handler.handlePullRequest(client, context, config)
879889

880890
// THEN
881-
expect(addAssigneesSpy.mock.calls[0][0].assignees).toHaveLength(1)
882-
expect(addAssigneesSpy.mock.calls[0][0].assignees[0]).toMatch(/assignee/)
891+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees).toHaveLength(1)
892+
expect(addAssigneesSpy.mock.calls[0][0]?.assignees![0]).toMatch(/assignee/)
883893

884-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(5)
885-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
894+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(5)
895+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
886896
/group1-reviewer/
887897
)
888-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[2]).toMatch(
898+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![2]).toMatch(
889899
/group2-reviewer/
890900
)
891-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[3]).toMatch(
901+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![3]).toMatch(
892902
/group3-reviewer/
893903
)
894904
})
@@ -901,7 +911,7 @@ describe('handlePullRequest', () => {
901911
filterLabels: { include: ['test_label'] },
902912
} as any
903913

904-
context.payload.pull_request.labels = [{ name: 'some_label' }]
914+
context.payload.pull_request!.labels = [{ name: 'some_label' }]
905915

906916
await handler.handlePullRequest(client, context, config)
907917

@@ -918,7 +928,7 @@ describe('handlePullRequest', () => {
918928
filterLabels: { include: ['test_label'], exclude: ['wip'] },
919929
} as any
920930

921-
context.payload.pull_request.labels = [
931+
context.payload.pull_request!.labels = [
922932
{ name: 'test_label' },
923933
{ name: 'wip' },
924934
]
@@ -951,7 +961,7 @@ describe('handlePullRequest', () => {
951961
reviewers: ['reviewer1', 'reviewer2', 'reviewer3', 'pr-creator'],
952962
} as any
953963

954-
context.payload.pull_request.labels = [{ name: 'some_label' }]
964+
context.payload.pull_request!.labels = [{ name: 'some_label' }]
955965

956966
const client = github.getOctokit('token')
957967

@@ -964,8 +974,8 @@ describe('handlePullRequest', () => {
964974
await handler.handlePullRequest(client, context, config)
965975

966976
expect(addAssigneesSpy).not.toBeCalled()
967-
expect(requestReviewersSpy.mock.calls[0][0].reviewers).toHaveLength(3)
968-
expect(requestReviewersSpy.mock.calls[0][0].reviewers[0]).toMatch(
977+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers).toHaveLength(3)
978+
expect(requestReviewersSpy.mock.calls[0][0]?.reviewers![0]).toMatch(
969979
/reviewer/
970980
)
971981
})

__tests__/run.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ describe.only('run', () => {
6060
return 'token'
6161
case 'configuration-path':
6262
return '.github/auto_assign.yml'
63+
default:
64+
return ''
6365
}
6466
})
6567

jest.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ module.exports = {
88
'^.+\\.ts$': 'ts-jest'
99
},
1010
verbose: true,
11-
globals: {
12-
'ts-jest': {
13-
tsconfig: './__tests__/tsconfig.jest.json'
14-
}
15-
}
11+
transform: {
12+
'^.+\\.(ts|tsx)$': 'ts-jest'
13+
},
1614
}

0 commit comments

Comments
 (0)